Vijey Vijey - 1 year ago 124
AngularJS Question

Angularjs: $scope vs scope

In Angularjs, is there a specific reason to use

in controllers and
) in directives link function? Is it just a convention or anything else?

Answer Source

The case when you do $scope in controller the Dependency Injection injects scope based on matching the variable name $scope, in this case using scope as name would not work.

For case of directive the injection is position based so you can name your variable a or b or any thing. The directive order for link function is

(scope, iElement, iAttrs, controller)

so first element is always scope object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download