Objective
In angular, Directive, service, Filter, controller are all given in a factory method, and the parameter names of the factory method correspond to the Service that the factory method relies on. ANGULARJS controller is actually a method, it has three kinds of writing, let's take a look together.
First type:
<pre name= "Code" class= "javascript" >var AppController = [' $scope ', function ($scope) {
$ Scope.notifyserviceonchage = function () {
console.log ($scope. windowheight);
};}
];
When definedAppController, first declare the parameters that the method needs to inject, and then define the method body. Finally, it will beAppControllerbound to the app.
The second type:
App.controller (' AppController ', function ($scope) {
$scope. notifyserviceonchage = function () {
Console.log ($scope. windowheight);
};
Directly in the app's controller attribute definition, first is the controller name, then the method body.
The third type:
function AppController ($scope) {
$scope. notifyserviceonchage = function () {
console.log ($scope. windowheight );
};
}
Write the method directly, and thenng-controllerrefer to the method
Summarize
The above is about ANGULARJS controller three kinds of writing all content, do not know that we have learned no, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.