看angularjs项目的一些知识记录

这两天项目组长在安排我学习用angularjs+Echarts做的项目代码,边看边记录吧,给自己留个总结

1.Angularjs中UI Router文档

2.Angularjs中Material的使用

3.requirejs文档

几个指令特点记录

1.ng-value中可以写表达式

<input type="text" ng-value="price*num"/>

2.当我们点击checkbox 选中复选框时,ng-model 的绑定默认值是true,取消选中时为false.

如果我们需要获取的值为字符串或者数字,那么就需要用到 ng-true-valueng-false-value

<input ng-model="checkboxModel" type="checkbox" ng-true-value=" 1 " ng-false-value="0">

3.angular中的工具函数:

    ①、遍历angular.forEach(data,function(el,i){})

    ②、转大小写

    ③、深拷贝:angular.copy:

    ④、处理json:angular.toJson(json对象转字符串)/angular.fromJson(json字符串转对象)

    ⑤、扩展对象:angular.extend(dst, src),把src中可以枚举的属性全部封装到dst对象上面

4.ng-click绑定事件,事件执行完后会进行脏检查;用js或jquery绑定事件,需要绑定$apply()函数才会执行脏检查

{{name}}
<button ng-click="change()">点击</button>
<hr>
{{name}}
<button id="btn">获取</button>

$scope.name="张飞";
$scope.change=function(){
    $scope.name="刘备";
}

var btn=document.getElementById('btn');
btn.onclick=function(){
    $scope.name='关羽';
    $scope.$apply();
}

 5.$scope绑定的数据到页面上都会转换成字符串,如果想把标签字符串转换成标签,需要用到$sce服务:

.controller("moduleCtrl",function($scope,$sce){
    $scope.name=$sce.trustAsHtml("<h1 style='color:red;'>张飞</h1>");
})

页面元素需要写成

<div ng-bind-html="name"></div>
原文地址:https://www.cnblogs.com/iagw/p/6599749.html