AngularJs First Knowledge

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.