Understanding the Controller
In angular, a container is a JavaScript constructor that is used to enhance the angular Scope.
When a controller is bound to dom,angular through the Ng-controller directive, a new controller object is instantiated, using the specific controller's constructor. A child scope is created, and the child scope is passed to the Controller constructor via the $scope parameter.
Using the controller:
Sets the initial state of the $scope object, such as some assigned initial values. )
Adding behavior to a $scope object
Do not use the controller:
Manipulating the DOM: The controller should contain only business logic. Putting any presentation logic in the controllers will affect testability. Angular can use data-binding and instructions to encapsulate DOM operations enough to handle most of the situation.
Format input: Use angular form controls to implement.
Formatted output: implemented using angular filters.
Share code or state between controllers: implemented using angular services.
Manage the life cycle of other components (for example, create a service instance)
Set the initial state of the $scope object
In general, when you create an app, you set the initial state of the angular $scope object. Set the initial state of scope by binding properties to the $scope object. The properties contain the View Model view models (models shown with views).
The following example shows the creation of a greetingcontroller, binding greeting property (containing string hola) to $scope.
"The English translation into Chinese, always feel very awkward, or directly to see the English ..." 】
"AngularJS" Controller