如何从指令中的其他模块调用方法

How to call method from other module in directive

本文关键字:其他 模块 调用 方法 指令      更新时间:2023-12-07

我的应用程序是这样的:

angular.module('app', [
    // other includes
    'ui.bootstrap'
])

在我的指令中,我正在处理:

angular.module('app').directive('DateFields','DatepickerController', ['$timeout', 'DatepickerController', function ($timeout, DatepickerControlle) {
return {
    restrict: 'A',
    replace: true,
    templateUrl: 'path to calendar.html',
    scope: {
        element: "=",
        flowParameterMap: "=?"
    },
    controller: ['$scope', '$element', '$timeout', function (scope, element,  $timeout) {
        if (!scope.element)
            return;
        scope.overlayClick = function (e)
        {
            scope.isOpen = true;
            var input = $(e.currentTarget).next();
            $timeout(function () {
                $(input).focus();
                $DatepickerController.isOpen = true;
            });              
        }

    }]
};
}]);

正如您所看到的,我正在尝试从datepickers isOpen变量的代码更改值来显示绑定到另一个dom对象的datepicker。但我所有的尝试都以"未定义"错误告终。

在你的指令中试试这个:

scope: {
    element: "=",
    isOpen: "=",
    flowParameterMap: "=?"
},

现在您应该能够更改isOpen值。