NOBLE M.O.
NOBLE M.O.

Reputation: 194

How to use $inject for declaration of angular dependencies

I'm developing an MVC application with angular JS. I have enabled the minification of scripts using

BundleTable.EnableOptimizations = true;

in the BundleConfig.cs. To avoid minification of dependency variable I used injection as given below.

app.controller("HomeController", ['$scope', 'HomeService', 'DTOptionsBuilder', 'DTColumnBuilder', 'DTColumnDefBuilder', HomeController]);

HomeController is the name of the function. It is working fine. Recently I found that, we can user controllerName.$inject to do the same. SO I tried it as given below.

HomeController.$inject['$scope', 'HomeService', 'DTOptionsBuilder', 'DTColumnBuilder', 'DTColumnDefBuilder'];

It didn't worked for me. Before doing this, I tried this method in a test project with only $scope variable. it worked. So what is the issue and how can I fix this. Please help me.

Upvotes: 0

Views: 88

Answers (1)

Grundy
Grundy

Reputation: 13380

You should see in doc

$inject is a property that you should fill, like this

HomeController.$inject = ['$scope', 'HomeService', 'DTOptionsBuilder', 'DTColumnBuilder', 'DTColumnDefBuilder'];

Upvotes: 1

Related Questions