我有一个配置文件更新指令,我想从父范围触发更新操作。这里看起来像我的代码:
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 ??? */
}
};
});
索引.html
<div ng-controller="Ctrl">
<profile updateFromDirective="updateFromController"></profile>
<button ng-click="updateFromController()">Update</button>
</div>