发表于: 2017-05-24 22:43:35
1 867
今天完成的事情:
学习了angular下拉菜单自定义指令的编写。
明天的计划:
检查任务6-10的代码,通过demo。
遇到的问题:
1 angular代码奇怪的执行两次:
var mainApp = angular.module('main',[]);
mainApp.controller('mainCtrl', function($scope, $http, $state){
// 折叠刷新保持状态
$('.dropMenu div:first-child').on('click',function () {
alert('abijavja');
});
不知道是不是后面代码的指令逻辑导致这段jq代码重复执行了,暂时未找出原因。
2手风琴指令的关键理解:
app.directive('myDirective',function(){
return {
restrict: 'A',
priority: 0,
//这个参数用来告诉AngularJS停止运行当前元素上比本指令优先级低的指令。但同当前指令优先级相同的指令还是会被执行。
terminal: false,
template: '',
//从指定的url地址加载模板
templateUrl: '',
//如果设置了这个参数,值必须为true 替换指令元素或插入内部
replace: false,
//创建一个能够从外部原型继承作用域的指令,将scope属性设置为true
scope: {
ngModel: '=', // 将ngModel同指定对象绑定
onSend: '&', // 将引用传递给这个方法
fromName: '@' // 储存与fromName相关联的字符串
}
//如果设置了,其值必须为true,它的默认值是false。
transclude:'',
controller:function($scope, $element, $attrs, $transclude) {
},
controllerAs: '',
//
require: '',
//以编程的方式操作DOM,包括添加监听器等
link: function postLink(scope, iElement, iAttrs) {},
//
compile: // 返回一个对象或连接函数,如下所示:
function(tElement, tAttrs, transclude) {
return {
pre: function(scope, iElement, iAttrs, controller) { },
post: function(scope, iElement, iAttrs, controller) { }
}
// 或者
return function postLink() { }
};
};
})
收获:以上。
评论