从其他控制器调用指令控制器中的方法
2022-08-30 05:17:53
						我有一个指令,它有自己的控制器。请参阅以下代码:
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');
    }
});
因此,在调用指令控制器时,还应触发链接函数并执行动画。我怎样才能做到这一点?showpopdown