Controller.$inject
时间: 2023-09-07 16:14:04 浏览: 88
`Controller.$inject` is a property of an AngularJS controller that specifies the dependencies of the controller. It is an array of strings, where each string is the name of a service or factory that the controller depends on.
For example, if a controller depends on the `$http` service and a custom `myService` factory, the `$inject` property would look like this:
```
MyController.$inject = ['$http', 'myService'];
function MyController($http, myService) {
// controller logic here
}
```
This syntax is used to explicitly declare the dependencies of the controller, which is useful for minification of code. When the code is minified, variable names can be changed, which could break the dependency injection if it is not explicitly declared using `$inject`.
阅读全文