独自のコントローラーを持つディレクティブがあります。以下のコードを参照してください。
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');
}
});
show
そのため、ディレクティブ コントローラーを呼び出すときpopdown
は、リンク関数もトリガーされ、アニメーションを実行する必要があります。どうすればそれを達成できますか?