I am trying to figure this one out but it seems google is not my friend today so I'm going to ask you guys here. Basically 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.model('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?
popdown
directive on the page - is it just in one place where other controllers are supposed to all have access to it, or are there several popdowns in different places? – satchmorun Feb 14 at 21:00