我有一个拥有自己的控制器的指令。请参见以下代码:
var popdown = angular.module('xModules',[]);
popdown.directive('popdown', function () {
var PopdownController = function ($scope) {
this.scope = $scope;
}
PopdownController.prototype = {
show:function (message, type) {
this.scope.message = message;
this.scope.type = type;
},
hide:function () {
this.scope.message = '';
this.scope.type = '';
}
}
var linkFn = function (scope, lElement, attrs, controller) {
};
return {
controller: PopdownController,
link: linkFn,
replace: true,
templateUrl: './partials/modules/popdown.html'
}
});
这是一个错误/通知/警告的通知系统。我想要做的是从另一个控制器(不是指令控制器)调用这个控制器上的函数show
。当我这样做的时候,我还希望我的链接函数检测到一些属性发生了变化,并执行一些动画。
下面是一些代码来举例说明我所要求的:
var app = angular.module('app', ['RestService']);
app.controller('IndexController', function($scope, RestService) {
var result = RestService.query();
if(result.error) {
popdown.notify(error.message, 'error');
}
});
因此,当在popdown
指令控制器上调用show
时,链接函数也应该被触发并执行动画。我怎样才能做到这一点呢?
https://stackoverflow.com/questions/14883476
复制相似问题