【发布时间】:2016-09-06 11:13:49
【问题描述】:
我有一个配置文件更新指令,我想从父范围触发更新操作。 这里看起来像我的代码:
main.js
angular.module('app')
.directive('profile',{
scope: {
updateFromDirective: "="
},
template: '<form><input ng-model="name"/></form>',
controller: function(){
this.updateFromDirective = function(){
/* update here */
};
}
})
.controller('Ctrl', function(){
this.updateFromController = function(){
if(condition){
/* how do I call updateFromDirective here ??? */
}
};
});
index.html
<div ng-controller="Ctrl">
<profile updateFromDirective="updateFromController"></profile>
<button ng-click="updateFromController()">Update</button>
</div>
【问题讨论】:
-
你到底要在这里做什么?什么是错误?
-
当点击更新触发器updateFromController然后调用updateFromDirective,它在将updateFromDirective传递给rootScope时起作用
-
分享 plunker 示例,我会看看错误出现在哪里。
-
请重新定义你的问题,理解起来有点棘手,你在父控制器中有一个按钮和一个动作,你的指令中需要一个函数,它有什么用?
标签: angularjs data-binding isolate-scope