angular.js/docs/content/guide/dev_guide.templates.ngdoc

58 lines
2.4 KiB
Text
Raw Normal View History

2011-06-06 15:50:35 +00:00
@ngdoc overview
@name Developer Guide: Understanding Angular Templates
@description
2012-09-26 13:30:55 +00:00
An Angular template is the declarative specification that, along with information from the model
2011-06-06 15:50:35 +00:00
and controller, becomes the rendered view that a user sees in the browser. It is the static DOM,
containing HTML, CSS, and angular-specific elements and angular-specific element attributes. The
2012-09-26 13:30:55 +00:00
Angular elements and attributes direct angular to add behavior and transform the template DOM into
2011-06-06 15:50:35 +00:00
the dynamic view DOM.
2012-09-26 13:30:55 +00:00
These are the types of Angular elements and element attributes you can use in a template:
2011-06-06 15:50:35 +00:00
* {@link guide/directive Directive} — An attribute or element that
2012-03-14 06:00:30 +00:00
augments an existing DOM element or represents a reusable DOM component - a widget.
* {@link api/ng.$interpolate Markup} — The double
2011-06-06 15:50:35 +00:00
curly brace notation `{{ }}` to bind expressions to elements is built-in angular markup.
* {@link dev_guide.templates.filters Filter} — Formats your data for display to the user.
2012-05-24 21:49:47 +00:00
* {@link forms Form controls} — Lets you validate user input.
2011-06-06 15:50:35 +00:00
Note: In addition to declaring the elements above in templates, you can also access these elements
in JavaScript code.
2012-09-26 13:30:55 +00:00
The following code snippet shows a simple Angular template made up of standard HTML tags along with
Angular {@link guide/directive directives} and curly-brace bindings
2012-05-24 21:49:47 +00:00
with {@link expression expressions}:
2011-06-06 15:50:35 +00:00
<pre>
2012-03-14 02:36:09 +00:00
<html ng-app>
<!-- Body tag augmented with ngController directive -->
2012-03-14 02:36:09 +00:00
<body ng-controller="MyController">
<input ng-model="foo" value="bar">
<!-- Button tag with ng-click directive, and
2011-06-06 15:50:35 +00:00
string expression 'buttonText'
wrapped in "{{ }}" markup -->
2012-03-14 02:36:09 +00:00
<button ng-click="changeFoo()">{{buttonText}}</button>
2012-01-07 02:10:47 +00:00
<script src="angular.js">
2011-06-06 15:50:35 +00:00
</body>
</html>
</pre>
In a simple single-page app, the template consists of HTML, CSS, and angular directives contained
in just one HTML file (usually `index.html`). In a more complex app, you can display multiple views
within one main page using "partials", which are segments of template located in separate HTML
files. You "include" the partials in the main page using the {@link api/ngRoute.$route
$route} service in conjunction with the {@link api/ngRoute.directive:ngView ngView} directive. An
2011-06-06 15:50:35 +00:00
example of this technique is shown in the {@link tutorial/ angular tutorial}, in steps seven and
eight.
## Related Topics
* {@link dev_guide.templates.filters Angular Filters}
2012-05-24 21:49:47 +00:00
* {@link forms Angular Forms}
2011-06-06 15:50:35 +00:00
## Related API
* {@link api/index API Reference}