X Tutup
Skip to content

Commit 2835265

Browse files
gnomeontherunIgorMinar
authored andcommitted
docs(cheatsheet) adding JS specific syntax to cheatsheet
Closes angular#5861
1 parent e950dd6 commit 2835265

File tree

10 files changed

+138
-49
lines changed

10 files changed

+138
-49
lines changed

modules/angular2/docs/cheatsheet/bootstrapping.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
Bootstrapping
33
@cheatsheetIndex 0
44
@description
5-
{@target js ts}`import {bootstrap} from 'angular2/platform/browser';`{@endtarget}
5+
{@target ts}`import {bootstrap} from 'angular2/angular2';`{@endtarget}
6+
{@target js}Available from the `ng.platform.browser` namespace.{@endtarget}
67
{@target dart}`import 'package:angular2/bootstrap.dart';`{@endtarget}
78

89
@cheatsheetItem
9-
syntax:
10+
syntax(ts dart):
1011
`bootstrap​(MyAppComponent, [MyService, provide(...)]);`|`provide`
12+
syntax(js):
13+
`document.addEventListener('DOMContentLoaded', function () {
14+
ng.platform.browser.bootstrap(MyAppComponent,
15+
[MyService, ng.core.provide(...)]);
16+
});`|`provide`
1117
description:
12-
Bootstraps an application with MyAppComponent as the root component, and
13-
configures the app's dependency injection providers.
18+
Bootstraps an application with MyAppComponent as the root component and configures the DI providers. {@target js}Must be wrapped in the event listener to fire when the page loads.{@endtarget}

modules/angular2/docs/cheatsheet/built-in-directives.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Built-in directives
33
@cheatsheetIndex 2
44
@description
5-
{@target js ts}`import {NgIf, ...} from 'angular2/common';`{@endtarget}
5+
{@target ts}`import {NgIf, ...} from 'angular2/common';`{@endtarget}
6+
{@target js}Available from the `ng.common` namespace{@endtarget}
67
{@target dart}`import 'package:angular2/common.dart';`{@endtarget}
78

89
@cheatsheetItem

modules/angular2/docs/cheatsheet/class-decorators.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,48 @@
22
Class decorators
33
@cheatsheetIndex 4
44
@description
5-
{@target js ts}`import {Directive, ...} from 'angular2/core';`{@endtarget}
5+
{@target ts}`import {Directive, ...} from 'angular2/core';`{@endtarget}
6+
{@target js}Available from the `ng.core` namespace{@endtarget}
67
{@target dart}`import 'package:angular2/core.dart';`{@endtarget}
78

89
@cheatsheetItem
9-
syntax(js ts):
10+
syntax(ts):
1011
`@Component({...})
1112
class MyComponent() {}`|`@Component({...})`
13+
syntax(js):
14+
`var MyComponent = ng.core.Component({...}).Class({...})`|`ng.core.Component({...})`
1215
syntax(dart):
1316
`@Component(...)
1417
class MyComponent() {}`|`@Component(...)`
1518
description:
1619
Declares that a class is a component and provides metadata about the component.
1720

1821
@cheatsheetItem
19-
syntax(js ts):
22+
syntax(ts):
2023
`@Pipe({...})
2124
class MyPipe() {}`|`@Pipe({...})`
25+
syntax(js):
26+
`var MyPipe = ng.core.Pipe({...}).Class({...})`|`ng.core.Pipe({...})`
2227
syntax(dart):
2328
`@Pipe(...)
2429
class MyPipe() {}`|`@Pipe(...)`
2530
description:
2631
Declares that a class is a pipe and provides metadata about the pipe.
2732

2833
@cheatsheetItem
29-
syntax(js ts):
34+
syntax(ts):
3035
`@Injectable()
3136
class MyService() {}`|`@Injectable()`
37+
syntax(js):
38+
`var MyService = ng.core.Class({constructor: [OtherService, function(otherService) { }]});
39+
var OtherService = ng.core.Class({constructor: function() { }});`
40+
var MyService = ng.core.Injectable({...})`|`ng.core.Injectable({...})`
3241
syntax(dart):
3342
`@Injectable()
3443
class MyService() {}`|`@Injectable()`
3544
description:
36-
Declares that a class has dependencies that should be injected into the constructor when the dependency
37-
injector is creating an instance of this class.
45+
{@target ts dart}Declares that a class has dependencies that should be injected into the constructor when the dependency injector is creating an instance of this class.
46+
{@endtarget}
47+
{@target js}
48+
Declares a service to inject into a class by providing an array with the services with the final item being the function which will receive the injected services.
49+
{@endtarget}

modules/angular2/docs/cheatsheet/component-configuration.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
Component configuration
33
@cheatsheetIndex 6
44
@description
5-
`@Component` extends `@Directive`,
6-
so the `@Directive` configuration applies to components as well
5+
{@target js}`ng.core.Component` extends `ng.core.Directive`,
6+
so the `ng.core.Directive` configuration applies to components as well{@endtarget}
7+
{@target ts dart}`@Component` extends `@Directive`,
8+
so the `@Directive` configuration applies to components as well{@endtarget}
79

810
@cheatsheetItem
9-
syntax:
11+
syntax(ts dart):
1012
`viewProviders: [MyService, provide(...)]`|`viewProviders:`
13+
syntax(js):
14+
`viewProviders: [MyService, ng.core.provide(...)]`|`viewProviders:`
1115
description:
1216
Array of dependency injection providers scoped to this component's view.
1317

modules/angular2/docs/cheatsheet/dependency-injection.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
22
Dependency injection configuration
33
@cheatsheetIndex 9
44
@description
5-
{@target js ts}`import {provide} from 'angular2/core';`{@endtarget}
5+
{@target ts}`import {provide} from 'angular2/core';`{@endtarget}
6+
{@target js}Available from the `ng.core` namespace{@endtarget}
67
{@target dart}`import 'package:angular2/core.dart';`{@endtarget}
78

89
@cheatsheetItem
9-
syntax:
10+
syntax(ts dart):
1011
`provide(MyService, {useClass: MyMockService})`|`provide`|`useClass`
12+
syntax(js):
13+
`ng.core.provide(MyService, {useClass: MyMockService})`|`provide`|`useClass`
1114
description:
1215
Sets or overrides the provider for MyService to the MyMockService class.
1316

1417

1518
@cheatsheetItem
16-
syntax:
19+
syntax(ts dart):
1720
`provide(MyService, {useFactory: myFactory})`|`provide`|`useFactory`
21+
syntax(js):
22+
`ng.core.provide(MyService, {useFactory: myFactory})`|`provide`|`useFactory`
1823
description:
1924
Sets or overrides the provider for MyService to the myFactory factory function.
2025

2126

2227
@cheatsheetItem
23-
syntax:
28+
syntax(ts dart):
29+
`provide(MyValue, {useValue: 41})`|`provide`|`useValue`
30+
syntax(js):
2431
`provide(MyValue, {useValue: 41})`|`provide`|`useValue`
2532
description:
2633
Sets or overrides the provider for MyValue to the value 41.
27-

modules/angular2/docs/cheatsheet/directive-and-component-decorators.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,79 @@
22
Class field decorators for directives and components
33
@cheatsheetIndex 7
44
@description
5-
{@target js ts}`import {Input, ...} from 'angular2/core';`{@endtarget}
5+
{@target ts}`import {Input, ...} from 'angular2/core';`{@endtarget}
6+
{@target js}Available from the `ng.core` namespace{@endtarget}
67
{@target dart}`import 'package:angular2/core.dart';`{@endtarget}
78

89
@cheatsheetItem
9-
syntax:
10+
syntax(ts dart):
1011
`@Input() myProperty;`|`@Input()`
12+
syntax(js):
13+
`ng.core.Input(myProperty, myComponent);`|`ng.core.Input(`|`);`
1114
description:
1215
Declares an input property that we can update via property binding (e.g.
1316
`<my-cmp [my-property]="someExpression">`).
1417

1518

1619
@cheatsheetItem
17-
syntax:
20+
syntax(ts dart):
1821
`@Output() myEvent = new EventEmitter();`|`@Output()`
22+
syntax(js):
23+
`myEvent = new ng.core.EventEmitter(); ng.core.Output(myEvent, myComponent);`|`ng.core.Output(`|`);`
1924
description:
2025
Declares an output property that fires events to which we can subscribe with an event binding (e.g. `<my-cmp (my-event)="doSomething()">`).
2126

2227

2328
@cheatsheetItem
24-
syntax:
29+
syntax(ts dart):
2530
`@HostBinding('[class.valid]') isValid;`|`@HostBinding('[class.valid]')`
31+
syntax(js):
32+
`ng.core.HostBinding('[class.valid]', 'isValid', myComponent);`|`ng.core.HostBinding('[class.valid]', 'isValid'`|`);`
2633
description:
2734
Binds a host element property (e.g. CSS class valid) to directive/component property (e.g. isValid).
2835

2936

3037

3138
@cheatsheetItem
32-
syntax:
39+
syntax(ts dart):
3340
`@HostListener('click', ['$event']) onClick(e) {...}`|`@HostListener('click', ['$event'])`
41+
syntax(js):
42+
`ng.core.HostListener('click', ['$event'], onClick(e) {...}, myComponent);`|`ng.core.HostListener('click', ['$event'], onClick(e)`|`);`
3443
description:
3544
Subscribes to a host element event (e.g. click) with a directive/component method (e.g. onClick), optionally passing an argument ($event).
3645

3746

3847
@cheatsheetItem
39-
syntax:
48+
syntax(ts dart):
4049
`@ContentChild(myPredicate) myChildComponent;`|`@ContentChild(myPredicate)`
50+
syntax(js):
51+
`ng.core.ContentChild(myPredicate, 'myChildComponent', myComponent);`|`ng.core.ContentChild(myPredicate,`|`);`
4152
description:
4253
Binds the first result of the component content query (myPredicate) to the myChildComponent property of the class.
4354

4455

4556
@cheatsheetItem
46-
syntax:
57+
syntax(ts dart):
4758
`@ContentChildren(myPredicate) myChildComponents;`|`@ContentChildren(myPredicate)`
59+
syntax(js):
60+
`ng.core.ContentChildren(myPredicate, 'myChildComponents', myComponent);`|`ng.core.ContentChildren(myPredicate,`|`);`
4861
description:
4962
Binds the results of the component content query (myPredicate) to the myChildComponents property of the class.
5063

5164

5265
@cheatsheetItem
53-
syntax:
66+
syntax(ts dart):
5467
`@ViewChild(myPredicate) myChildComponent;`|`@ViewChild(myPredicate)`
68+
syntax(js):
69+
`ng.core.ViewChild(myPredicate, 'myChildComponent', myComponent);`|`ng.core.ViewChild(myPredicate,`|`);`
5570
description:
5671
Binds the first result of the component view query (myPredicate) to the myChildComponent property of the class. Not available for directives.
5772

5873

5974
@cheatsheetItem
60-
syntax:
75+
syntax(ts dart):
6176
`@ViewChildren(myPredicate) myChildComponents;`|`@ViewChildren(myPredicate)`
77+
syntax(js):
78+
`ng.core.ViewChildren(myPredicate, 'myChildComponents', myComponent);`|`ng.core.ViewChildren(myPredicate,`|`);`
6279
description:
6380
Binds the results of the component view query (myPredicate) to the myChildComponents property of the class. Not available for directives.

modules/angular2/docs/cheatsheet/directive-configuration.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Directive configuration
33
@cheatsheetIndex 5
44
@description
5-
{@target js ts}`@Directive({ property1: value1, ... })`{@endtarget}
5+
{@target ts}`@Directive({ property1: value1, ... })`{@endtarget}
6+
{@target js}`ng.core.Directive({ property1: value1, ... }).Class({...})`{@endtarget}
67
{@target dart}`@Directive(property1: value1, ...)`{@endtarget}
78

89
@cheatsheetItem
@@ -15,7 +16,9 @@ Specifies a CSS selector that identifies this directive within a template. Suppo
1516
Does not support parent-child relationship selectors.
1617

1718
@cheatsheetItem
18-
syntax:
19+
syntax(ts dart):
1920
`providers: [MyService, provide(...)]`|`providers:`
21+
syntax(js):
22+
`providers: [MyService, ng.core.provide(...)]`|`providers:`
2023
description:
2124
Array of dependency injection providers for this directive and its children.

modules/angular2/docs/cheatsheet/forms.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Forms
33
@cheatsheetIndex 3
44
@description
5-
{@target js ts}`import {FORM_DIRECTIVES} from 'angular2/common';`{@endtarget}
5+
{@target ts}`import {FORM_DIRECTIVES} from 'angular2/common';`{@endtarget}
6+
{@target js}Available from `ng.common.FORM_DIRECTIVES`{@endtarget}
67
{@target dart}`import 'package:angular2/common.dart';`{@endtarget}
78

89
@cheatsheetItem

modules/angular2/docs/cheatsheet/lifecycle hooks.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,87 @@
22
Directive and component change detection and lifecycle hooks
33
@cheatsheetIndex 8
44
@description
5-
(implemented as class methods)
5+
{@target ts dart}(implemented as class methods){@endtarget}
6+
{@target js}(implemented as component properties){@endtarget}
67

78
@cheatsheetItem
8-
syntax(js ts):
9+
syntax(ts):
910
`constructor(myService: MyService, ...) { ... }`|`constructor(myService: MyService, ...)`
11+
syntax(js):
12+
`constructor: function(MyService, ...) { ... }`|`constructor: function(MyService, ...)`
1013
syntax(dart):
1114
`MyAppComponent(MyService myService, ...) { ... }`|`MyAppComponent(MyService myService, ...)`
1215
description:
1316
The class constructor is called before any other lifecycle hook. Use it to inject dependencies, but avoid any serious work here.
1417

1518

1619
@cheatsheetItem
17-
syntax:
20+
syntax(ts dart):
1821
`ngOnChanges(changeRecord) { ... }`|`ngOnChanges(changeRecord)`
22+
syntax(js):
23+
`ngOnChanges: function(changeRecord) { ... }`|`ngOnChanges: function(changeRecord)`
1924
description:
2025
Called after every change to input properties and before processing content or child views.
2126

2227

2328
@cheatsheetItem
24-
syntax:
29+
syntax(ts dart):
2530
`ngOnInit() { ... }`|`ngOnInit()`
31+
syntax(js):
32+
`ngOnInit: function() { ... }`|`ngOnInit: function()`
2633
description:
2734
Called after the constructor, initializing input properties, and the first call to ngOnChanges.
2835

2936

3037
@cheatsheetItem
31-
syntax:
38+
syntax(ts dart):
3239
`ngDoCheck() { ... }`|`ngDoCheck()`
40+
syntax(js):
41+
`ngDoCheck: function() { ... }`|`ngDoCheck: function()`
3342
description:
3443
Called every time that the input properties of a component or a directive are checked. Use it to extend change detection by performing a custom check.
3544

3645

3746
@cheatsheetItem
38-
syntax:
47+
syntax(ts dart):
3948
`ngAfterContentInit() { ... }`|`ngAfterContentInit()`
49+
syntax(js):
50+
`ngAfterContentInit: function() { ... }`|`ngAfterContentInit: function()`
4051
description:
4152
Called after ngOnInit when the component's or directive's content has been initialized.
4253

4354

4455
@cheatsheetItem
45-
syntax:
56+
syntax(ts dart):
4657
`ngAfterContentChecked() { ... }`|`ngAfterContentChecked()`
58+
syntax(js):
59+
`ngAfterContentChecked: function() { ... }`|`ngAfterContentChecked: function()`
4760
description:
4861
Called after every check of the component's or directive's content.
4962

5063

5164
@cheatsheetItem
52-
syntax:
65+
syntax(ts dart):
5366
`ngAfterViewInit() { ... }`|`ngAfterViewInit()`
67+
syntax(js):
68+
`ngAfterViewInit: function() { ... }`|`ngAfterViewInit: function()`
5469
description:
5570
Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
5671

5772

5873
@cheatsheetItem
59-
syntax:
74+
syntax(ts dart):
6075
`ngAfterViewChecked() { ... }`|`ngAfterViewChecked()`
76+
syntax(js):
77+
`ngAfterViewChecked: function() { ... }`|`ngAfterViewChecked: function()`
6178
description:
6279
Called after every check of the component's view. Applies to components only.
6380

6481

6582
@cheatsheetItem
66-
syntax:
83+
syntax(ts dart):
6784
`ngOnDestroy() { ... }`|`ngOnDestroy()`
85+
syntax(js):
86+
`ngOnDestroy: function() { ... }`|`ngOnDestroy: function()`
6887
description:
6988
Called once, before the instance is destroyed.

0 commit comments

Comments
 (0)
X Tutup