<!doctype html><html xmlns:ng="http://angularjs.org" ng-app><body>...<script src="angular.js"></body></html利用ngapp标示你需要自动引导应用程序的根节点,一般典型为html tag。在DOMContentLoaded事件触发Angular会自动寻找ngapp作为应用的根节点,如果找到则会进行如下操作:
<!doctype html><html ng-app="optionalModuleName"><body>I can add: {{ + }}.<script src="angular.js"></script></body></html>2:手动初始化:<!doctype html><html xmlns:ng="http://angularjs.org"><body>Hello {{"World"}}!<script src="http://code.angularjs.org/angular.js"></script><script>angular.element(document).ready(function() {angular.bootstrap(document);});</script></body></html>1.在页面所有代码加载完成后,找到html模板根节点(典型为document元素).<span ng-bind="exp"></span><span class="ng-bind: exp;"></span><ng-bind></ng-bind><!-- directive: ng-bind exp –>directive仅仅是一个在dom中会被Angular执行的一个function。下面是一个拖拽的实例,其可以被应用于span,div的attribute上:
angular.module("drag", []).directive("draggable", function ($document) { var startX = , startY = , x = , y = ; return function (scope, element, attr) { element.css({ position: "relative", border: "px solid red", backgroundColor: "lightgrey", cursor: "pointer" }); element.bind("mousedown", function (event) { startX = event.screenX - x; startY = event.screenY - y; $document.bind("mousemove", mousemove); $document.bind("mouseup", mouseup); }); function mousemove(event) { y = event.screenY - startY; x = event.screenX - startX; element.css({ top: y + "px", left: x + "px" }); } function mouseup() { $document.unbind("mousemove", mousemove); $document.unbind("mouseup", mouseup); } } });Demo 
而Angular则不同利用directive指令而非字符串,返回值是一个合并数据model的link function。view和model的绑定是自动,透明的,不需要开发人员添加额外的action去更新view,Angular在这里不仅是数据model的绑定,还有行为概念。作为双向的绑定,形如下图:

资料:
1.Angular官网:http://angularjs.org/
2.代码下载:https://github.com/angular/angular.js
以上所述是小编给大家介绍的Angular的Bootstrap(引导)和Compiler(编译)机制,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!