Moment For Technology

Refer to the manual AngularJS

Posted on Aug. 6, 2022, 1:47 a.m. by Divit Rattan
Category: The front end Tag: javascript The front end

Reference manualAngularJS

for

 div data - ng - app = "" data - ng - init =" names = [' Jani ', 'Hege', 'Kai'] "  p  use ng - repeat to circular array  / p   ul   li data - ng - repeat =" in x names" {{ x }} /li /ul /divCopy the code
div ng-app="myApp" ng-controller="myCtrl"

ul
    li ng-repeat="x in names"{{x}}/li
/ul

/div

script
var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) {
    $scope.names = ["Emil", "Tobias", "Linus"];
});
/script
Copy the code

ng-app ng-controller angular.module

div ng-app="myApp" ng-controller="myCtrl" input ng-model="name" /div script var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.name = "John Doe"; }); /scriptCopy the code

Two-way binding

scope

Scope is the link between HTML (view) and JavaScript (controller) that applies. Scope is an object with available methods and properties.

div ng-app="myApp" ng-controller="myCtrl"

h1{{carname}}/h1

/div

script
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.carname = "Volvo";
});
/script
Copy the code
button ng-click='sayHello()' /buttonCopy the code

AngularJS services (Service)

var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $location) {
    $scope.myUrl = $location.absUrl();
});
Copy the code

Send the request

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
  $http.get("welcome.htm").then(function (response) {
      $scope.myWelcome = response.data;
  });
});
Copy the code

timeout interval

var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $timeout) { $scope.myHeader = "Hello World!" ; $timeout(function () { $scope.myHeader = "How are you today?" ; }, 2000); });Copy the code
ng-disabled
ng-show
ng-hide
Copy the code

directive

div ng-app="myApp" runoob-directive/div script var app = angular.module("myApp", []); App. directive("runoobDirective", function() {return {template: "I created in the directive constructor!" }; });Copy the code

contains

div ng-include="'runoob.htm'"/div The ng-include directive does not allow files containing other domain names. If you need a file with another domain name, You need to set up the domain name visit white list app. Config (function ($sceDelegateProvider) {$sceDelegateProvider. ResourceUrlWhitelist ([ 'https://c.runoob.com/runoobtest/**' ]); }); div ng-include="'https://c.runoob.com/runoobtest/angular_include.php'"/divCopy the code

Dependency injection

routing

Search
About
mo4tech.com (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.