Initialization of Angular. js basic learning and angular. js Initialization

Source: Internet
Author: User

Initialization of Angular. js basic learning and angular. js Initialization

I. Bind initialization and automatic loading

Through Binding to initialize angular, js Code will be infiltrated into html.

ng-appIs an angular command, representing an angular application (also called a module ). Useng-appOrng-app=""To mark a DOM node so that the framework will automatically load the node. That is to say,ng-appIt can contain attribute values.

<body ng-app="myApp"> <div ng-controller="myCtrl">  {{ hello }} </div> <script type="text/javascript">  var myModule = angular.module("myApp",[]);  myModule.controller("myCtrl",function($scope){   $scope.hello = "hello,angular!";  }); </script></body>

Ii. Manual Initialization

If you want to have more control over initialization, you can use a custom manual Bootstrap Method to initialize instead of angular's automatic initialization. For example, you need to do something before angular compiles the template, for example, changing the template content.

Angular also provides manually bound api -- bootstrap, which is used as follows:

angular.bootstrap(element, [modules], [config]);

The first parameterelement:Yesng-appDom element;

  • Modules: name of the bound Module
  • Config: Additional configuration

It is worth noting that:

  • angular.bootstrapOnly the objects loaded for the first time will be bound.
  • Duplicate binding or binding of other objects will be prompted on the console.
<Html> 

Summary

The above is about angular. I hope the content in this article can be learned or used by you. js can provide some help. If you have any questions, you can leave a message. Thank you for your support.

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.