Skip to content

Instantly share code, notes, and snippets.

@rependa
Last active October 22, 2015 16:02
Show Gist options
  • Select an option

  • Save rependa/0942eabef3940be15f1e to your computer and use it in GitHub Desktop.

Select an option

Save rependa/0942eabef3940be15f1e to your computer and use it in GitHub Desktop.
XmVGpJ
<div ng-app="" ng-init="firstName='John'">'
<p>Name: <input type="text" ng-model="name"></p>
<p ng-bind="name"></p>
<hr/>
<p>The name is <span ng-bind="firstName"></span></p>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>

AngularJS Directives

The ng-app directive tells AngularJS that the <div> element is the "owner" of an AngularJS application.

The ng-model Directive

The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.

The ng-model directive can also:

  • Provide type validation for application data (number, email, required).
  • Provide status for application data (invalid, dirty, touched, error).
  • Provide CSS classes for HTML elements.
  • Bind HTML elements to HTML forms.

The ng-bind directive binds the innerHTML of the <p> element to the application variable name.

The ng-init Directive

The ng-init directive defines initial values for an AngularJS application.

Normally, you will not use ng-init. You will use a controller or module instead.

The ng-repeat Directive

The ng-repeat directive clones HTML elements once for each item in a collection (in an array).

A Pen by Matt Rependa on CodePen.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment