我有一个配置文件更新指令,我想从父范围触发更新动作。 这里是什么样子的我的代码:将指令动作绑定到父控制器AngularJS
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时共同工作 – Ayoub
共享plunker示例,所以我会看到错误在哪里gettting。 –