2015-11-13 02:14:12 -05:00
@cheatsheetSection
Template syntax
@cheatsheetIndex 1
@description
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<input [value]="firstName">` |`[value]`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Binds property `value` to the result of expression `firstName` .
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<div [attr.role]="myAriaRole">` |`[attr.role]`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Binds attribute `role` to the result of expression `myAriaRole` .
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<div [class.extra-sparkle]="isDelightful">` |`[class.extra-sparkle]`
2015-12-09 07:33:42 -05:00
description:
2015-12-10 12:52:19 -05:00
Binds the presence of the CSS class `extra-sparkle` on the element to the truthiness of the expression `isDelightful` .
2015-11-13 02:14:12 -05:00
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<div [style.width.px]="mySize">` |`[style.width.px]`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Binds style property `width` to the result of expression `mySize` in pixels. Units are optional.
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<button (click)="readRainbow($event)">` |`(click)`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Calls method `readRainbow` when a click event is triggered on this button element (or its children) and passes in the event object.
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<div title="Hello {{ponyName}}">` |`{{ponyName}}`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Binds a property to an interpolated string, e.g. "Hello Seabiscuit". Equivalent to:
`<div [title]="'Hello' + ponyName">`
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<p>Hello {{ponyName}}</p>` |`{{ponyName}}`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Binds text content to an interpolated string, e.g. "Hello Seabiscuit".
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<my-cmp [(title)]="name">` |`[(title)]`
2015-12-09 07:33:42 -05:00
description:
2015-11-23 19:02:19 -05:00
Sets up two-way data binding. Equivalent to: `<my-cmp [title]="name" (titleChange)="name=$event">`
2015-11-13 02:14:12 -05:00
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`< video #movieplayer ... >
< button ( click ) = " movieplayer . play ( ) " >
< / video > `|`#movieplayer`|`(click)`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Creates a local variable `movieplayer` that provides access to the `video` element instance in data-binding and event-binding expressions in the current template.
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<p *my-unless="myExpression">...</p>` |`*my-unless`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
The `*` symbol means that the current element will be turned into an embedded template. Equivalent to:
`<template [myless]="myExpression"><p>...</p></template>`
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<p>Card No.: {{cardNumber | myCreditCardNumberFormatter}}</p>` |`{{cardNumber | myCreditCardNumberFormatter}}`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
Transforms the current value of expression `cardNumber` via the pipe called `creditCardNumberFormatter` .
@cheatsheetItem
2015-12-09 07:33:42 -05:00
syntax:
2015-11-13 02:14:12 -05:00
`<p>Employer: {{employer?.companyName}}</p>` |`{{employer?.companyName}}`
2015-12-09 07:33:42 -05:00
description:
2015-11-13 02:14:12 -05:00
The Elvis operator (`?`) means that the `employer` field is optional and if `undefined` , the rest of the expression should be ignored.