Angular Notes
@(yuanhangguo)[angularjs]
Dependency Injection
Components in Angular:
- Services
- Directives
- Filters
- Animations
Controller
Naming convention
__S__picyController
Born
- use
ng-controller
to identify which controller (attached controller). - Angular will instantiate the controller use the constructor .
- Angular will create a new child scope via injected
$scope
.ng-controller
directive is used to implicitly create a scope. - use
angular.module('moduleName", []).controller('controllerName', ['$scope', dep1', 'dep2', function($scope, dep1, dep2) {
// 1. give initialize value to $scope
// 2. add behaviour to $scope
}])
For
- give initialize value to
$scope
- add behaviour to
$scope
Scope
Can be accessed by template/view
and ng
event handler directives like ngClick
.
Not for
- Manipulate DOM (angular directive and data binding will do)
- Formatting input (angular form control's job)
- Filter output (angular filter's job)
- Share code with other controller (angular service's job)
- Manage lifecycle of other components (create other services, etc)
Related Directive
ng-controller
directive is used to implicitly create a scope.
网友评论