There are likely other problems with your code preventing it from working, 
but just to be sure *you do need to include ‘product’ in your DI injection 
array*.

The DI injection arrays are not just for services, but for anything that 
needs to be injected by name. You can get away with not using an array 
notation at all and it will work fine. For example:

var productDetailController = 
catalogControllers.controller('ProductDetailController', function($scope, 
product) {
            console.log(product);

            $scope.product = product;
            $scope.mainImageUrl = product.images[0].path; // cannot read 
'images' of undefined

            $scope.SetImage = function(imageUrl) {
                $scope.mainImageUrl = imageUrl;
            }
        } 
);

In this case dependency injection will work (because angular will just use 
toString() on the function to read in the parameter names. The purpose of 
the DI array notation is to help in the case the variables in the function 
don’t match the names of the services or other objects that are being 
injected. This can happen if you simply want to name the parameters in your 
function differently than their service names or most often as part of 
variable mangling that happens during minification.

Take for example what you had written:

var productDetailController = 
catalogControllers.controller('ProductDetailController',
    ['$scope',
        function($scope, product) {
           ....
        }
    ]
);

When mangled by a minifier it might look like:

var a = b.c('ProductDetailController',
    ['$scope',  function(d, e) {
           ....
        }
    ]
);

If you don’t include ['$scope', 'product', function(d, e) { ...}] how will 
angular know that you need ‘product’ to go in the ‘e’ parameter? 

DI array notation is all or nothing. Basically, if you are using the DI 
array notation you *MUST* include all the parameters that your function 
takes (even resolve parameters not just services).

As far as other things that may be wrong with your code, it’s kind of hard 
to tell unless you create a sample on plunkr. I suspect it has to do with 
how you set up your javascript files and what you are doing in your 
services.

For example, I don’t know how you are setting up your modules and resolves. 
It looks like you are doing weird things. For example:

var productDetailController = 
catalogControllers.controller('ProductDetailController', ...);

I am assuming catalogControllers is a module, in which case calling 
.controller() will not return a controller, but will return the 
catalogControllers module instead. So it’s weird that then you attatch the 
resolve to the module:

productDetailController.resolve =  ....

If you were doing this in more than one place, the resolve would get 
clobbered each time. What you want to do is probably something like this:

var productDetailController = ['$scope', 'product', function($scope, product){
 .....
}];

productDetailController.resolve = { ..... };
catalogControllers.controller('ProductDetailController', 
productDetailController);

I don’t know that that’s your actual issue (although it is quite possible 
if you are defining other controllers in a similar fashion in your 
testing). 

So first fix your DI array or don’t use DI array notation. Then try fixing 
your controller definition. If neither works then please try to create an 
example on plunker or jsfiddle, otherwise it is very difficult to help find 
the problem.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to