3

I'm trying to follow this answer to an older question, but I'm getting a crash on $parse as the function parameter. Why might it not recognize $parse?

https://stackoverflow.com/a/29571230/1481314

.directive('elementReady', function ($parse) {
            return {
                restrict: 'A',
                link: function ($scope, elem, attrs) {
                    elem.ready(function () {
                        $scope.$apply(function () {
                            var func = $parse(attrs.elementReady);
                            func($scope);
                        })
                    })
                }
            }
        });
Community
  • 1
  • 1
Danny Ellis Jr.
  • 1,674
  • 2
  • 23
  • 38

1 Answers1

0

You need to specify the injection in string format. This is only needed when uglifying your source code.

Approach 1: use array format when declaring angular injections

.directive('elementReady', ['$parse' function elementReady($parse) {
  ... 
}]);

Approach 2: use named function and manually specify injection

.directive('elementReady', elementReady)

function elementReady($parse) {
  ... 
}
elementReady.$inject = ['$parse'];

Approach 3: use ng-annotation to automate this

GRUNT: https://www.npmjs.com/package/grunt-ng-annotate

GULP: https://www.npmjs.com/package/gulp-ng-annotate/

Henry Zou
  • 1,809
  • 1
  • 14
  • 19