Skip to content

ngInject not being transformed when directive controller is inside of directive closure #62

Closed
@johnpapa

Description

@johnpapa

When a directive uses a controller and that controller needs // @ngInject syntax it is not being caught when it is defined within the directive closure.

(function () {
    'use strict';

    angular
        .module('app')
        .directive('foo', foo);

    /**
     * @returns {Object} - Directive definition object
     */
    function foo() {
        return {
            restrict: 'EA',
            scope: true,
            transclude: false,
            templateUrl: 'foo.html',
            controller: FooCtrl
        };

        /**
         * @ngInject
         */
        function FooCtrl($scope) {
            var vm = $scope.bar = {
                timeFormat: 'H:mma'
            };
        }
}
}());

Yet this does work when I moved the controller outside the directive.

(function () {
    'use strict';

    angular
        .module('app')
        .directive('foo', foo);

    /**
     * @returns {Object} - Directive definition object
     */
    function foo() {
        return {
            restrict: 'EA',
            scope: true,
            transclude: false,
            templateUrl: 'foo.html',
            controller: FooCtrl
        };
    }

    /**
     * @ngInject
     */
    function FooCtrl($scope) {
        var vm = $scope.bar = {
            timeFormat: 'H:mma'
        };
    }
}());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions