Angularjs 基础入门

这篇文章主要介绍了Angularjs 基础入门的一些知识,需要的朋友可以参考下

针对于这个其实我不太清楚应该针对于哪些人或者说不知道从哪开始写,所以这里我就按照一种简单的思路开始写

1.angular.element
2.angular.Bootstrap

我们非常清楚ng-app应用到节点,angular自动帮你初始化,初始化的过程分为如下几个步骤

1.angular会在document load的时候自动初始化,首先会找到ng-app这个指令指定的节点。
2.加载与module相关的指令
3.创建与应用相关的injector(依赖管理器)
4.以制定的ng-app为根节点,开始对Dom进行compile

现在我们自己初始化一下,做一个等同于ng-app这个指令的东西。angular.element这个就是包装,包装原始DOM元素或HTML字符串作为jQuery元素。angular.Bootstrap可以手动初始化脚本,我们用这两个来初始化这个脚本

复制代码 代码如下:


  
  
  
  Bootstrap-manual
  
  
  
  这里是ng-app外面的~~{{1+2}}
  
这里是ng-app里面~~~ {{1+2}}

  
  
  
  

2.compiler

我们清楚的看到angularjs的官方文档上边都是驼峰式命名法,譬如ngApp、ngModule、ngBind等等这些都是相关的指令,其中html compiler就是允许我们自己定义元素 属性和标签,Angular将这些附加行为称为directives。
官方文档对compiler的解释是这样的

复制代码 代码如下:

Compiler
  Compiler is an Angular service which traverses the DOM looking for attributes. The compilation process happens in two phases.

  Compile: traverse the DOM and collect all of the directives. The result is a linking function.

  Link: combine the directives with a scope and produce a live view. Any changes in the scope model are reflected in the view, and any user interactions with the view are reflected in the scope model. This makes the scope model the single source of truth.

  Some directives such as ng-repeat clone DOM elements once for each item in a collection. Having a compile and link phase improves performance since the cloned template only needs to be compiled once, and then linked once for each clone instance.

以上就是Angularjs 基础入门的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Angular.js 答疑