发表于: 2017-04-10 23:34:42
2 1072
今天完成的事:
学习angular。
自定义filter
app.filter('my_price',function () {
//外层函数,只执行一次,初始化
return function (input,arg) {
//内层函数,用几次执行几次,多次
alert(arg);
if(input<0){
return '('+input+')';
}
}
})
directive 自定义标签——自定义组件。
app.directive('abc',function () {
var json1={
restrict:'E', //约束,指令能用在哪里
template:'<span>1.自定义的abc标签E</span>'
};
return json1;
});
restict:
E element 元素 <xxx></xxx>
A attribute 属性 <div xxx=""></div>
C class 类 <div class="xxx"></>
M comment 注释 <!-- directive:xxx --> 两边空格必须
加上replace:true
有一个小坑:命名html里是my-close中划线,对应js中myClose 驼峰法。如果js中命名myClose,那么html里要写成my-close。
对ng的用法加深理解。学习了自定义依赖注入。
创造依赖的方法有,最简单的是工厂模式
app.factory('name',function(){
return ...内容
});
比较强大的方式provider:
app.provider("name",function(){
this.$get=function(){}
}
明天要做的是:任务7。
遇到的问题:看视频学习可能还是比较慢。
收获:对angular加深理解。
评论