简体   繁体   中英

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.

You should see in doc

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM