【发布时间】:2017-09-15 06:14:53
【问题描述】:
我想将另一个控制器的值放到我的自定义指令中,但是指令中 watch 函数中的值未定义。这是我的代码:
指令代码:
function associates($templateCache,$compile) {
var directive = {};
directive.restrict = 'E';
directive.controller = 'associatesTypeaheadController';
directive.controllerAs = 'ctrlTA';
directive.template = $templateCache.get('typeahead.template.html');
directive.scope= {
"options": '='
};
directive.link=link;
return directive;
}
function link(scope, element, attrs) {
scope.$watch('options.reload', function(data){
console.log(data); //Still undefined
});
}
控制器:
employeeDetails.opts = {
"reload": false,
"refresh": false
};
employeeDetails.reload = function () {
employeeDetails.opts.reload = true;
console.log('there');
return employeeDetails.opts.reload;
};
employeeDetails.reload();
【问题讨论】:
-
你能粘贴一些包含指令元素的 html 来显示绑定是否正确吗?我希望像
标签: angularjs angularjs-directive