Angular Notes

作者: Yuanhang | 来源:发表于2015-04-05 10:07 被阅读0次

Angular Notes

@(yuanhangguo)[angularjs]

Dependency Injection

Components in Angular:

  1. Services
  2. Directives
  3. Filters
  4. Animations

Controller

Naming convention

__S__picyController

Born

  1. use ng-controller to identify which controller (attached controller).
  2. Angular will instantiate the controller use the constructor .
  3. Angular will create a new child scope via injected $scope. ng-controller directive is used to implicitly create a scope.
  4. 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

  1. give initialize value to $scope
  2. add behaviour to $scope

Scope

Can be accessed by template/view and ng event handler directives like ngClick.

Not for

  1. Manipulate DOM (angular directive and data binding will do)
  2. Formatting input (angular form control's job)
  3. Filter output (angular filter's job)
  4. Share code with other controller (angular service's job)
  5. Manage lifecycle of other components (create other services, etc)

Related Directive

ng-controller directive is used to implicitly create a scope.

相关文章

网友评论

    本文标题:Angular Notes

    本文链接:https://www.haomeiwen.com/subject/jciaxttx.html