Minify and injector

1,992 views
Skip to first unread message

zhhz

unread,
May 7, 2012, 2:09:00 PM5/7/12
to AngularJS
Hello,

Not sure I'm doing it the angular way.

I am playing with the angular-phonecat app (https://github.com/angular/
angular-phonecat.git), it works well until I minified the services.js.
I've added this line to the controller.js:

PhoneDetailCtrl.$inject = ['$scope', '$routeParams', 'Phone'];

Here is error info:

Error: Unknown provider: aProvider <- a <- Phone ("aProvider")@http://
localhost:8000/app/lib/angular/angular.js:2492
getService("aProvider")@http://localhost:8000/app/lib/angular/
angular.js:2620 ("a")@http://localhost:8000/app/lib/angular/angular.js:
2497 getService("a",[object Array])@http://localhost:8000/app/lib/
angular/angular.js:2620

Anyone can help me out this? (I'm using closure compiler with the
simple optimize switch turned on)

Thanks.

--zhhz

Peter Bacon Darwin

unread,
May 7, 2012, 2:34:45 PM5/7/12
to ang...@googlegroups.com
Try defining your controllers inside a module...

app/controllers.js file
angular.module('controllers',[]).controller('PhoneDetailCtrl', ['$scope', '$routeParams', 'Phone', function ($scope, $routeParams, Phone) {
...
}]);

app/app.js
angular.module('phonecat', ['phonecatFilters', 'phonecatServices', 'controllers'])...


--zhhz

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Igor Minar

unread,
May 8, 2012, 2:16:22 AM5/8/12
to ang...@googlegroups.com
Looks like you missed some $inject or []-style annotations.

It's likely going to be the Phone service in services.js. You should change:

factory('Phone', function($resource){ ... }))

to

factory('Phone', ['$resource', function($resource){ ... })])


/i




--zhhz

ZHHZ

unread,
May 8, 2012, 10:59:58 AM5/8/12
to ang...@googlegroups.com
Thank you Igor. It works like a charm. I can't believe I missed that part. Thanks a gain.

--zhhz


On Tuesday, May 8, 2012 2:16:22 AM UTC-4, Igor Minar wrote:
Looks like you missed some $inject or []-style annotations.

It's likely going to be the Phone service in services.js. You should change:

factory('Phone', function($resource){ ... }))

to

factory('Phone', ['$resource', function($resource){ ... })])


/i



Hello,

Not sure I'm doing it the angular way.

I am playing with the angular-phonecat app (https://github.com/angular/
angular-phonecat.git
), it works well until I minified the services.js.
I've added this line to the controller.js:

PhoneDetailCtrl.$inject = ['$scope', '$routeParams', 'Phone'];

Here is error info:

Error: Unknown provider: aProvider <- a <- Phone ("aProvider")@http://
localhost:8000/app/lib/angular/angular.js:2492
getService("aProvider")@http://localhost:8000/app/lib/angular/
angular.js:2620 ("a")@http://localhost:8000/app/lib/angular/angular.js:
2497 getService("a",[object Array])@http://localhost:8000/app/lib/
angular/angular.js:2620


Anyone can help me out this? (I'm using closure compiler with the
simple optimize switch turned on)

Thanks.

--zhhz

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
/i



Hello,

Not sure I'm doing it the angular way.

I am playing with the angular-phonecat app (https://github.com/angular/
angular-phonecat.git
), it works well until I minified the services.js.
I've added this line to the controller.js:

PhoneDetailCtrl.$inject = ['$scope', '$routeParams', 'Phone'];

Here is error info:

Error: Unknown provider: aProvider <- a <- Phone ("aProvider")@http://
localhost:8000/app/lib/angular/angular.js:2492
getService("aProvider")@http://localhost:8000/app/lib/angular/
angular.js:2620 ("a")@http://localhost:8000/app/lib/angular/angular.js:
2497 getService("a",[object Array])@http://localhost:8000/app/lib/
angular/angular.js:2620


Anyone can help me out this? (I'm using closure compiler with the
simple optimize switch turned on)

Thanks.

--zhhz

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Deepak Patil

unread,
Apr 17, 2014, 8:38:57 AM4/17/14
to ang...@googlegroups.com, zhongh...@gmail.com
If you miss the array notation somewhere , to locate this we need to modify the angular code little bit, but its very quick solution.

change is console.log("Array Notation is Missing",fn); ( line no 11 from function start)

Find out annotate function in angular.js (non-minified)

  

    function annotate(fn) {
          var $inject,
              fnText,
              argDecl,
              last;
        
          if (typeof fn == 'function') {
            if (!($inject = fn.$inject)) {
              $inject = [];
              if (fn.length) {
    console.log("Array Notation is Missing",fn);
    fnText = fn.toString().replace(STRIP_COMMENTS, '');
            argDecl = fnText.match(FN_ARGS);
            forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){
              arg.replace(FN_ARG, function(all, underscore, name){
                $inject.push(name);
              });
            });
          }
          fn.$inject = $inject;
        }
      } else if (isArray(fn)) {
        last = fn.length - 1;
        assertArgFn(fn[last], 'fn');
        $inject = fn.slice(0, last);
      } else {
        assertArgFn(fn, 'fn', true);
      }
      return $inject;
Reply all
Reply to author
Forward
0 new messages