2015-11-06 07:26:24 -05:00
|
|
|
@cheatsheetSection
|
|
|
|
Class field decorators for directives and components
|
2015-11-13 02:14:12 -05:00
|
|
|
@cheatsheetIndex 7
|
2015-11-05 10:04:55 -05:00
|
|
|
@description
|
2015-12-11 18:01:37 -05:00
|
|
|
{@target js ts}`import {Input, ...} from 'angular2/core';`{@endtarget}
|
|
|
|
{@target dart}`import 'package:angular2/core.dart';`{@endtarget}
|
2015-11-05 10:04:55 -05:00
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-05 10:04:55 -05:00
|
|
|
`@Input() myProperty;`|`@Input()`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-12-10 12:52:19 -05:00
|
|
|
Declares an input property that we can update via property binding (e.g.
|
|
|
|
`<my-cmp [my-property]="someExpression">`).
|
2015-11-05 10:04:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-05 10:04:55 -05:00
|
|
|
`@Output() myEvent = new EventEmitter();`|`@Output()`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-12-10 12:52:19 -05:00
|
|
|
Declares an output property that fires events to which we can subscribe with an event binding (e.g. `<my-cmp (my-event)="doSomething()">`).
|
2015-11-05 10:04:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-06 07:26:24 -05:00
|
|
|
`@HostBinding('[class.valid]') isValid;`|`@HostBinding('[class.valid]')`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-12-10 12:52:19 -05:00
|
|
|
Binds a host element property (e.g. CSS class valid) to directive/component property (e.g. isValid).
|
2015-11-05 10:04:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-05 10:04:55 -05:00
|
|
|
`@HostListener('click', ['$event']) onClick(e) {...}`|`@HostListener('click', ['$event'])`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-12-10 12:52:19 -05:00
|
|
|
Subscribes to a host element event (e.g. click) with a directive/component method (e.g. onClick), optionally passing an argument ($event).
|
2015-11-05 10:04:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-05 10:04:55 -05:00
|
|
|
`@ContentChild(myPredicate) myChildComponent;`|`@ContentChild(myPredicate)`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-11-05 10:04:55 -05:00
|
|
|
Binds the first result of the component content query (myPredicate) to the myChildComponent property of the class.
|
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-05 10:04:55 -05:00
|
|
|
`@ContentChildren(myPredicate) myChildComponents;`|`@ContentChildren(myPredicate)`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-11-05 10:04:55 -05:00
|
|
|
Binds the results of the component content query (myPredicate) to the myChildComponents property of the class.
|
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-05 10:04:55 -05:00
|
|
|
`@ViewChild(myPredicate) myChildComponent;`|`@ViewChild(myPredicate)`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-11-05 10:04:55 -05:00
|
|
|
Binds the first result of the component view query (myPredicate) to the myChildComponent property of the class. Not available for directives.
|
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-09 07:33:42 -05:00
|
|
|
syntax:
|
2015-11-05 10:04:55 -05:00
|
|
|
`@ViewChildren(myPredicate) myChildComponents;`|`@ViewChildren(myPredicate)`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-12-09 13:22:40 -05:00
|
|
|
Binds the results of the component view query (myPredicate) to the myChildComponents property of the class. Not available for directives.
|