I have a directive that has its own controller. See the below code:
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'
}
});
This is meant to be a notification system for errors/notifications/warnings. What I want to do is from another controller (not a directive one) to call the function show
on this controller. And when I do that, I would also want my link function to detect that some properties changed and perform some animations.
Here is some code to exemplify what I'm asking for:
var app = angular.module('app', ['RestService']);
app.controller('IndexController', function($scope, RestService) {
var result = RestService.query();
if(result.error) {
popdown.notify(error.message, 'error');
}
});
So when calling show
on the popdown
directive controller, the link function should also be triggered and perform an animation. How could I achieve that?