AngularJS : minification issue in directive

前端 未结 2 555
广开言路
广开言路 2020-12-28 13:23

I have yet another issue with minification. This time it\'s because of the $scope service passed to the directive\'s controller. See below code:

angular.modu         


        
2条回答
  •  误落风尘
    2020-12-28 14:08

    You need to declare a controller as follows:

    controller: ['$scope', function ($scope)
        {                   
            $scope.test = 3;                   
        }]
    

    Full example here:

    angular.module('person.directives').
    directive("person", ['$dialog', function($dialog) {
    return {
        restrict: "E",
        templateUrl: "person/views/person.html",
        replace: true,
        scope: {
            myPerson: '='
        },     
        controller: ['$scope', function ($scope)
        {                   
            $scope.test = 3;                   
        }]
    }
    }]);
    

    A solution provided by @Sam would work to but it would mean exposing directive's controller to the whole application which is unnecessary.

提交回复
热议问题