Fork me on GitHub

This is a list of style choices and idioms we wish to apply when using AngularJs.

Access to Parent Scope

When a parameter is assigned in a template, it will sometimes need explicit access to the parent scope due to new child scopes being created by the parent elements in the template. For example:

  <directive-element>
    <div ng-if="cond">
      <form name="formName">
        ...
      </form>
    </div>
  </directive-element>

This will fail to give access to formName in the directiveElement controller. To expose the parent scope to the child directive we can do the following:

directiveElement.js

  $scope.scope = $scope

directiveElement.html

  <directive-element>
    <div ng-if="cond">
      <form name="scope.formName">
        ...
      </form>
    </div>
  </directive-element>

This naming convention for form elements is fully supported by Angular, and allows us to explicitly define which scope object the new element should be stored on.