angular-cn/docs/content/cheatsheet/class-decorators.md

50 lines
1.7 KiB
Markdown
Raw Normal View History

2015-11-06 07:26:24 -05:00
@cheatsheetSection
Class decorators
@cheatsheetIndex 5
2015-11-05 10:04:55 -05:00
@description
2016-08-08 20:25:42 -04:00
{@target ts}`import { Directive, ... } from '@angular/core';`{@endtarget}
{@target js}Available from the `ng.core` namespace{@endtarget}
2015-11-05 10:04:55 -05:00
@cheatsheetItem
syntax(ts):
2015-11-05 10:04:55 -05:00
`@Component({...})
class MyComponent() {}`|`@Component({...})`
syntax(js):
`var MyComponent = ng.core.Component({...}).Class({...})`|`ng.core.Component({...})`
description:
2015-11-05 10:04:55 -05:00
Declares that a class is a component and provides metadata about the component.
@cheatsheetItem
syntax(ts):
`@Directive({...})
class MyDirective() {}`|`@Directive({...})`
syntax(js):
`var MyDirective = ng.core.Directive({...}).Class({...})`|`ng.core.Directive({...})`
description:
Declares that a class is a directive and provides metadata about the directive.
2015-11-05 10:04:55 -05:00
@cheatsheetItem
syntax(ts):
2015-11-05 10:04:55 -05:00
`@Pipe({...})
class MyPipe() {}`|`@Pipe({...})`
syntax(js):
`var MyPipe = ng.core.Pipe({...}).Class({...})`|`ng.core.Pipe({...})`
description:
2015-11-05 10:04:55 -05:00
Declares that a class is a pipe and provides metadata about the pipe.
@cheatsheetItem
syntax(ts):
`@Injectable()
class MyService() {}`|`@Injectable()`
syntax(js):
`var OtherService = ng.core.Class(
{constructor: function() { }});
var MyService = ng.core.Class(
{constructor: [OtherService, function(otherService) { }]});`|`var MyService = ng.core.Class({constructor: [OtherService, function(otherService) { }]});`
description:
{@target ts}Declares that a class has dependencies that should be injected into the constructor when the dependency injector is creating an instance of this class.
{@endtarget}
{@target js}
Declares a service to inject into a class by providing an array with the services, with the final item being the function to receive the injected services.
{@endtarget}