| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 81bc706 commit a002ed1
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,20 @@ | |||
| 1 | 1 | # Templates | |
| 2 | 2 | ||
| 3 | - Templates are markup which is added to HTML to declarativly describe how the application model should be | ||
| 3 | + Templates are markup which is added to HTML to declaratively describe how the application model should be | ||
| 4 | 4 | projected to DOM as well as which DOM events should invoke which methods on the controller. Templates contain | |
| 5 | 5 | syntax which is core to Angular and allows for data-binding, event-binding, template-instantiation. | |
| 6 | 6 | ||
| 7 | 7 | The design of the template syntax has these properties: | |
| 8 | + | ||
| 8 | 9 | ||
| 9 | 10 | * All data-binding expressions are easily identifiable. (i.e. there is never an ambiguity whether the value should be | |
| 10 | 11 | interpreted as string literal or as an expression.) | |
| 11 | 12 | * All events and their statements are easily identifiable. | |
| 12 | 13 | * All places of DOM instantiation are easily identifiable. | |
| 13 | - * All places of variable declaration is easily identifiable. | ||
| 14 | + * All places of variable declaration are easily identifiable. | ||
| 14 | 15 | ||
| 15 | - The above properties guarantee that the templates are easily to be parsed by tools (such as IDEs) and reasoned about by people. | ||
| 16 | - At no point is it necessary to understand which directives are active and what are their semantics in order to reason | ||
| 16 | + The above properties guarantee that the templates are easy to parse by tools (such as IDEs) and reason about by people. | ||
| 17 | + At no point is it necessary to understand which directives are active or what their semantics are in order to reason | ||
| 17 | 18 | about the template runtime characteristics. | |
| 18 | 19 | ||
| 19 | 20 | ||
@@ -222,7 +223,11 @@ Example: | |||
| 222 | 223 | ||
| 223 | 224 | ## Property Binding | |
| 224 | 225 | ||
| 226 | + <<<<<<< HEAD | ||
| 225 | 227 | Binding application model data to the UI is the most common kind of bindings in an Angular application. The bindings | |
| 228 | + ======= | ||
| 229 | + Binding application model data to the UI is the most common type of binding in an Angular application. The bindings | ||
| 230 | + >>>>>>> upstream/pr/666 | ||
| 226 | 231 | are always in the form of `property-name` which is assigned an `expression`. The generic form is: | |
| 227 | 232 | ||
| 228 | 233 | <table> | |
@@ -253,7 +258,11 @@ its value. | |||
| 253 | 258 | ||
| 254 | 259 | Key points: | |
| 255 | 260 | * The binding is to the element property not the element attribute. | |
| 261 | + <<<<<<< HEAD | ||
| 256 | 262 | * To prevent custom element from accidentally reading the literal `expression` on the title element, the attribute name | |
| 263 | + ======= | ||
| 264 | + * To prevent a custom element from accidentally reading the literal `expression` on the title element, the attribute name | ||
| 265 | + >>>>>>> upstream/pr/666 | ||
| 257 | 266 | is escaped. In our case the `title` is escaped to `[title]` through the addition of square brackets `[]`. | |
| 258 | 267 | * A binding value (in this case `user.firstName` will always be an expression, never a string literal) | |
| 259 | 268 | ||
@@ -345,10 +354,10 @@ Where: | |||
| 345 | 354 | inserted. The template can be defined implicitly with `template` attribute, which turns the current element into | |
| 346 | 355 | a template, or explicitly with `<template>` element. Explicit declaration is longer, but it allows for having | |
| 347 | 356 | templates which have more than one root DOM node. | |
| 348 | - * `instantiating-directive` is required for templates. The instantiating directive is responsible for deciding when | ||
| 349 | - and in which order should child views be inserted into this location. An instantiating directive usually has one or | ||
| 350 | - more bindings and can be represented as either `instantiating-directive-bindings` or | ||
| 351 | - `instantiating-directive-microsyntax` on `template` element or attribute. See template microsyntax for more details. | ||
| 357 | + * `viewport` is required for templates. The Viewport directive is responsible for deciding when | ||
| 358 | + and in which order should child views be inserted into this location. An Viewport directive usually has one or | ||
| 359 | + more bindings and can be represented as either `viewport-directive-bindings` or | ||
| 360 | + `viewport-directive-microsyntax` on `template` element or attribute. See template microsyntax for more details. | ||
| 352 | 361 | ||
| 353 | 362 | ||
| 354 | 363 | Example of conditionally included template: | |
@@ -360,7 +369,7 @@ Hello {{user}}! | |||
| 360 | 369 | </div> | |
| 361 | 370 | ``` | |
| 362 | 371 | ||
| 363 | - In the above example the `if` instantiator determines whether the child view (an instance of the child template) should be | ||
| 372 | + In the above example the `if` Viewport determines whether the child view (an instance of the child template) should be | ||
| 364 | 373 | inserted into the root view. The `if` makes this decision based on if the `isAdministrator` binding is true. | |
| 365 | 374 | ||
| 366 | 375 | The above example is in the short form, for better clarity let's rewrite it in the canonical form, which is functionally | |
@@ -375,7 +384,7 @@ Hello {{user}}! | |||
| 375 | 384 | </template> | |
| 376 | 385 | ``` | |
| 377 | 386 | ||
| 378 | - NOTE: Only Instantiator directives can be placed on the template element. (Decorators and Components are not allowed.) | ||
| 387 | + NOTE: Only Viewport directives can be placed on the template element. (Decorators and Components are not allowed.) | ||
| 379 | 388 | ||
| 380 | 389 | ||
| 381 | 390 | ### Template Microsyntax | |
@@ -395,11 +404,11 @@ of the templates occurs. One such example is `foreach`. | |||
| 395 | 404 | ||
| 396 | 405 | Where: | |
| 397 | 406 | * `foreach` triggers the foreach directive. | |
| 398 | - * `[in]="people"` binds to an iterable object to the `foreach` controller. | ||
| 407 | + * `[in]="people"` binds an iterable object to the `foreach` controller. | ||
| 399 | 408 | * `#person` exports the implicit `foreach` item. | |
| 400 | 409 | * `#i=index` exports item index as `i`. | |
| 401 | 410 | ||
| 402 | - The above example is explicit but quite wordy, for this reason in most situations a short hand version of the | ||
| 411 | + The above example is explicit but quite wordy. For this reason in most situations a short hand version of the | ||
| 403 | 412 | syntax is preferable. | |
| 404 | 413 | ||
| 405 | 414 | ``` | |
@@ -446,7 +455,7 @@ Where | |||
| 446 | 455 | * `internal` is an internal variable which the directive exports for binding. | |
| 447 | 456 | * `key` is an attribute name usually only used to trigger a specific directive. | |
| 448 | 457 | * `keyExpression` is an property name to which the expression will be bound to. | |
| 449 | - * `varExport` allows exporting of a directive internal state as variable for further binding. If no `internal` name | ||
| 458 | + * `varExport` allows exporting of directive internal state as variables for further binding. If no `internal` name | ||
| 450 | 459 | is specified, the exporting is to an implicit variable. | |
| 451 | 460 | * `microsyntax` allows you to build a simple microsyntax which can still clearly identify which expressions bind to | |
| 452 | 461 | which properties as well as which variables are exported for binding. | |
@@ -475,12 +484,12 @@ Binding events allows wiring events from DOM (or other components) to the Angula | |||
| 475 | 484 | </table> | |
| 476 | 485 | ||
| 477 | 486 | Where: | |
| 478 | - * `some-element` Any element which can generate DOM events (or has angular directive which generates the event). | ||
| 487 | + * `some-element` Any element which can generate DOM events (or has an angular directive which generates the event). | ||
| 479 | 488 | * `some-event` (escaped with `()` or `bind-`) is the name of the event `some-event`. In this case the | |
| 480 | 489 | dash-case is converted into camel-case `someEvent`. | |
| 481 | 490 | * `statement` is a valid statement (as defined in section below). | |
| 482 | 491 | ||
| 483 | - By default angular only listens to the element on the event, and ignores events which bubble. To listen to bubbled | ||
| 492 | + By default, angular only listens to the element on the event, and ignores events which bubble. To listen to bubbled | ||
| 484 | 493 | events (as in the case of clicking on any child) use the bubble option (`(^event)` or `on-bubble-event`) as shown | |
| 485 | 494 | bellow. | |
| 486 | 495 | ||
@@ -508,13 +517,13 @@ class Example { | |||
| 508 | 517 | <button (click)="submit()">Submit</button> | |
| 509 | 518 | ``` | |
| 510 | 519 | ||
| 511 | - In the above example, when clicking on the submit button angular will invoke the `submit` method on the surounding | ||
| 520 | + In the above example, when clicking on the submit button angular will invoke the `submit` method on the surrounding | ||
| 512 | 521 | component's controller. | |
| 513 | 522 | ||
| 514 | 523 | ||
| 515 | 524 | NOTE: Unlike Angular v1, Angular v2 treats event bindings as core constructs not as directives. This means that there | |
| 516 | 525 | is no need to create a event directive for each kind of event. This makes it possible for Angular v2 to easily | |
| 517 | - bind to custom events of Custom Elements, whos event names are not known ahead of time. | ||
| 526 | + bind to custom events of Custom Elements, whose event names are not known ahead of time. | ||
| 518 | 527 | ||
| 519 | 528 | ||
| 520 | 529 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments