I am totally confused about inject in Angular. I do not know where to use it and why. Is it only used with factory as described here?
myController.$inject =
The way you should use $inject
is:
function ApplicationController($scope){
$scope.greet = "Foo is Not Great!5";
}
ApplicationController.$inject = ['$scope','$ionic'];
app.controller('ApplicationController', ApplicationController);
We need to this as to protect the code from uglifying or minimization.
function(firstName,lastName)
may get turned into function(n,m)
.
So for AngularJS it will break the code because $scope
can be replaced by 's'. This is because without the $
sign the angularJS won't be able to recognize the code.