1.
Angulari
NIT Initialization
The page has a ng-app instruction, if any, it is started, or if not, it needs to be started manually.
Auto Start:
if (appelement) {//If appelement exists, it executes.
Bootstrap (appelement, module?) [Module]: []);
}
2.provider and Injector
1. Dependency Injection
The simplest dependency of NG is inline injection, and it has 2 types, namely inferred injection and callout injection.
use $injector directly. * generally rarely used.
Inferred injection:
var mymodule = angualr.module ("MyModule", []);
var ctrl = function ($scope) {
$scope. Name = "2222";
}
mymodule.controller ("Ctrl", CTRL);
Callout Injection:
var mymodule = angualr.module ("MyModule", []);
var ctrl = function (name) {
name = "2222";
}
Ctrl. $inject = [' $scope '];
Syringe
Injector:
var mymodule = angualr.module ("MyModule", []);
mymodule.factory (' Game ', function () {
return {
Ganmename: ' 11111 '
}
}
mymodule.controller (' Myctrl ', [' $scope ', ' $injector ',
function ($scope, $injector) {
$injector. Invoke (function (game) {
Console.log (game.gamename);
]);
}
});
provider mode and NG implementations:
provider mode is a complex of strategy mode and factory model;
The core purpose is to make the interface and implementation separate;
in Ng, all provider are available for injection:
Provider/factory/service/constant/value
the type of function can accept injection:
controller/directive/filter/service/factory Germany
The "Dependency injection" in NG is a joint implementation of the 2 mechanisms of Ono Provider and Ijector;
var mymodule = angular.module ("MyModule", []);
Mymodule.provider ("Helloangular", function () {
return {
$get: function () {
var name= "SSS";
function GetName
() {
return name;
}
return {
Getname:getname
}
}
}
});
mymodule.controller (' Myctrl ', [' $scope ', ' helloangualr ',
function ($scope, helloangualr) {
$scope. Gamename = Helloangualr.getname ();
}])
AngularJs First Knowledge