> For the complete documentation index, see [llms.txt](https://note.niefee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://note.niefee.com/summary/3/2016-nian-3-yue-17-ri.md).

# 2016年3月17日

## javascript

### angularjs

* angularJs特性？
  * MVC模式
  * 模块系统
  * 指令系统
  * 依赖注入
  * 双向数据绑定
* angularJs的作用域
  * $scope
  * $rootScope
  * 依赖注入
  * 服务

```javascript
function Aaa($scope ,$rootScope){//依赖注入，形参不能改
    $scope.name='hello world!!';
    $rootScope.txt="nihao";//全局变量，
}
function Bbb($scope){
    $scope.name='Bbb hello world!!';
}
```

```markup
<div ng-controller='Aaa'>
    <p>{{name}}</p>
</div>
<div  ng-controller="Bbb">
    <span>{{txt}}</span>//会先在局部查找，然后在全局查找。
</div>
```

* angularJs的指令系统
  * ng-app
    * 初始化一个angularjs应用程序
  * ng-controller
    * 定义控制器
* angularJs的双向数据绑定
  * MVVM
  * $timeout
    * 有刷新功能
  * ng-click
    * click事件
  * ng-model
    * 绑定数据

```javascript
    function Aaa($scope,$timeout){
    $scope.name = 'hello';
    /*setTimeout(function(){
        $scope.name = 'hi';
    },2000);*/
    /*$timeout(function(){
        $scope.name = 'hi';
    },2000);*/

    $scope.show = function(){
        $scope.name = 'hi';
    };

}
```

```markup
<div ng-controller="Aaa" ng-click="show()">
    <p>{{name}}</p>
</div>
```

* 过滤器
  * currency

```markup
<span>{{all.money*all.num|currency:'@'}}</span>
```

* $watch
  * 监听数据变化
  * 三个参数
    * 第三个为**true**时可以监听一个整体，否则是单个。

```javascript
$scope.$watch($scope.sum,function(newVal,oldVal){
        //console.log(newVal);
        //console.log(oldVal);

$scope.iphone.fre = newVal >= 100 ? 0 : 10;

});
```
