bundling and minification - AngularJS directive fails when minified -
i'm using minifier addon visual studio works except 1 block of angularjs code
this unminified code:
var svgbuildinterface = angular.module("svgbuildinterface", []); svgbuildinterface.directive('ngrightclick', function ($parse) { return function (scope, element, attrs) { var fn = $parse(attrs.ngrightclick); element.bind('contextmenu', function (event) { scope.$apply(function () { event.preventdefault(); fn(scope, { $event: event }); }); }); }; });
this pretty-printed minified code fails:
svgbuildinterface = angular.module("svgbuildinterface", []); svgbuildinterface.directive("ngrightclick", function(n) { return function(t, i, r) { var u = n(r.ngrightclick); i.bind("contextmenu", function(n) { t.$apply(function() { n.preventdefault(); u(t, { $event: n }) }) }) } });
i can't put break point minified code find out happening, angularjs throws exception:
error: [$injector:unpr] http://errors.angularjs.org/1.5.7/ $injector/unpr?p0=nprovider%20%3c-%20n%20%3c-%20ngrightclickdirective
change directive below,there best practices followed when writing controller or directive or whatever component of angular js when want minify js.
one of them passing dependency injection via []
var svgbuildinterface = angular.module("svgbuildinterface", []); svgbuildinterface.directive('ngrightclick',['$parse', function ($parse) { return function (scope, element, attrs) { var fn = $parse(attrs.ngrightclick); element.bind('contextmenu', function (event) { scope.$apply(function () { event.preventdefault(); fn(scope, { $event: event }); }); }); }; }]);
Comments
Post a Comment