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-12-21 06:40:35 -05:00
`<p *myUnless="myExpression">...</p>` |`*myUnless`
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:
2015-12-21 06:40:35 -05:00
`<template [myUnless]="myExpression"><p>...</p></template>`
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
`<p>Card No.: {{cardNumber | myCreditCardNumberFormatter}}</p>` |`{{cardNumber | myCreditCardNumberFormatter}}`
2015-12-09 07:33:42 -05:00
description:
2016-01-11 07:14:51 -05:00
Transforms the current value of expression `cardNumber` via the pipe called `myCreditCardNumberFormatter` .
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
`<p>Employer: {{employer?.companyName}}</p>` |`{{employer?.companyName}}`
2015-12-09 07:33:42 -05:00
description:
2016-04-22 17:01:26 -04:00
The safe navigation operator (`?`) means that the `employer` field is optional and if `undefined` , the rest of the expression should be ignored.
2016-05-19 13:20:08 -04:00
@cheatsheetItem
syntax:
`<svg:rect x="0" y="0" width="100" height="100"/>` |`svg:`
description:
SVG snippet templates need an `svg:` prefix on their root element to disambiguate the SVG element from an HTML component.
@cheatsheetItem
syntax:
`< svg >
< rect x = "0" y = "0" width = "100" height = "100" / >
< / svg > `|`svg`
description:
`<svg>` root elements are detected as SVG element automatically without the prefix