AngularJS-在角度UI中的指令上配置装饰器

时间:2019-07-02 01:52:29

标签: angularjs angular-ui

当前,我正在使用angularjs 1.7和angular-ui / boostrap。 我想在用户单击下拉菜单时加载数据,但是我不想学习click事件,而是想了解更多有关angular js的信息,我更喜欢使用decorator来修改uibDropdownDirective。这是我的代码:

我在这里找到了类似的解决方案,但对我而言不起作用。 Angular decorator/extending UI Bootstrap Datepicker directive

angular.element(document).ready(() => {
    angular.bootstrap(document, ['myapp']);

    angular.module('myapp').config(['$provide', ($provide: any) => {
        $provide.decorator('uibDropdownDirective', [
            '$delegate', function ($delegate: any, $controller: any) {

                var directive = $delegate[0];
                var controllerName = directive.controller;

                directive.controller = function ($scope: any, $element: any, $attrs: any, $parse: any, dropdownConfig: any, uibDropdownService: any,
                    $animate: any, $position: any, $document: any, $compile: any, $templateRequest: any) {
                    var controller = $controller(controllerName, {
                        $scope,
                        $element,
                        $attrs,
                        $parse,
                        dropdownConfig,
                        uibDropdownService,
                        $animate,
                        $position,
                        $document,
                        $compile,
                        $templateRequest
                    });

                    $scope.toggled = function (open: any) {
                        console.log('Dropdown is now: ', open);
                        //Load data
                    };

                    return controller;
                };

                return directive;
            }
        ]);
    }]);
});

0 个答案:

没有答案