Angular Notes

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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容