AngularJS's controller is actually a method, it has three kinds of wording:
The first type:
[JavaScript]View PlainCopy
- <pre name="code" class="JavaScript" >var appcontroller = [' $scope ', function ($scope) {
- $scope. Notifyserviceonchage = function () {
- Console.log ($scope. windowheight);
- };
- }];
- App.controller (' AppController ', AppController);
When defining AppController, first declare the parameters that the method needs to inject, and then define the method body. Finally, bind the AppController to the app.
The second type:
[JavaScript]View PlainCopy
- App.controller (' appcontroller ', function ($scope) {
- $scope. Notifyserviceonchage = function () {
- Console.log ($scope. windowheight);
- };
- })
Directly in the app's Controller property definition, first the controller name, then the method body.
The third type:
[JavaScript]View PlainCopy
- function AppController ($scope) {
- $scope. Notifyserviceonchage = function () {
- Console.log ($scope. windowheight);
- };
- }
Write the method directly, and then reference the method in Ng-controller
Excerpt from: http://blog.csdn.net/teddyu_leo/article/details/49816721
Three ways to Angularjs a controller