Skip to content

Commit 778677b

Browse files
alxhubvsavkin
authored andcommitted
docs(core): Myriad of documentation changes including lots of new example code.
1 parent f0d876a commit 778677b

File tree

16 files changed

+306
-206
lines changed

16 files changed

+306
-206
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {Inject, Injector, forwardRef, resolveForwardRef, ForwardRefFn} from 'angular2/core';
2+
3+
// #docregion forward_ref_fn
4+
var ref = forwardRef(() => Lock);
5+
// #enddocregion
6+
7+
// #docregion forward_ref
8+
class Door {
9+
lock: Lock;
10+
constructor(@Inject(forwardRef(() => Lock)) lock: Lock) { this.lock = lock; }
11+
}
12+
13+
// Only at this point Lock is defined.
14+
class Lock {}
15+
16+
var injector = Injector.resolveAndCreate([Door, Lock]);
17+
var door = injector.get(Door);
18+
expect(door instanceof Door).toBe(true);
19+
expect(door.lock instanceof Lock).toBe(true);
20+
// #enddocregion
21+
22+
// #docregion resolve_forward_ref
23+
var ref = forwardRef(() => "refValue");
24+
expect(resolveForwardRef(ref)).toEqual("refValue");
25+
expect(resolveForwardRef("regularValue")).toEqual("regularValue");
26+
// #enddocregion
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {bootstrap} from 'angular2/bootstrap';
2+
import {NG_VALIDATORS} from 'angular2/common';
3+
import {Provider} from 'angular2/core';
4+
5+
let MyApp = null;
6+
let myValidator = null;
7+
8+
// #docregion ng_validators
9+
bootstrap(MyApp, [new Provider(NG_VALIDATORS, {useValue: myValidator, multi: true})]);
10+
// #enddocregion
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component} from 'angular2/core';
2+
import {bootstrap} from 'angular2/platform/browser';
3+
4+
// #docregion bootstrap
5+
@Component({selector: 'my-app', template: 'Hello {{ name }}!'})
6+
class MyApp {
7+
name: string = 'World';
8+
}
9+
10+
function main() {
11+
return bootstrap(MyApp);
12+
}
13+
// #enddocregion
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {Component, Attribute, Directive, Pipe} from 'angular2/core';
2+
3+
var CustomDirective;
4+
5+
// #docregion component
6+
@Component({selector: 'greet', template: 'Hello {{name}}!', directives: [CustomDirective]})
7+
class Greet {
8+
name: string = 'World';
9+
}
10+
// #enddocregion
11+
12+
// #docregion attributeFactory
13+
@Component({selector: 'page', template: 'Title: {{title}}'})
14+
class Page {
15+
title: string;
16+
constructor(@Attribute('title') title: string) { this.title = title; }
17+
}
18+
// #enddocregion
19+
20+
// #docregion attributeMetadata
21+
@Directive({selector: 'input'})
22+
class InputAttrDirective {
23+
constructor(@Attribute('type') type) {
24+
// type would be 'text' in this example
25+
}
26+
}
27+
// #enddocregion
28+
29+
// #docregion directive
30+
@Directive({selector: 'input'})
31+
class InputDirective {
32+
constructor() {
33+
// Add some logic.
34+
}
35+
}
36+
// #enddocregion
37+
38+
// #docregion pipe
39+
@Pipe({name: 'lowercase'})
40+
class Lowercase {
41+
transform(v, args) { return v.toLowerCase(); }
42+
}
43+
// #enddocregion
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component, platform} from 'angular2/core';
2+
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
3+
4+
var appProviders: any[] = [];
5+
6+
// #docregion longform
7+
@Component({selector: 'my-app', template: 'Hello World'})
8+
class MyApp {
9+
}
10+
11+
var app = platform(BROWSER_PROVIDERS).application([BROWSER_APP_PROVIDERS, appProviders]);
12+
app.bootstrap(MyApp);
13+
// #enddocregion
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import {
2+
describe,
3+
fdescribe,
4+
xdescribe,
5+
it,
6+
fit,
7+
xit,
8+
beforeEach,
9+
afterEach,
10+
beforeEachProviders,
11+
inject
12+
} from 'angular2/testing';
13+
import {provide} from 'angular2/core';
14+
15+
var db: any;
16+
class MyService {}
17+
class MyMockService implements MyService {}
18+
19+
// #docregion describeIt
20+
describe('some component', () => {
21+
it('does something', () => {
22+
// This is a test.
23+
});
24+
});
25+
// #enddocregion
26+
27+
// #docregion fdescribe
28+
fdescribe('some component', () => {
29+
it('has a test', () => {
30+
// This test will run.
31+
});
32+
});
33+
describe('another component',
34+
() => { it('also has a test', () => { throw 'This test will not run.'; }); });
35+
// #enddocregion
36+
37+
// #docregion xdescribe
38+
xdescribe('some component', () => { it('has a test', () => {throw 'This test will not run.'}); });
39+
describe('another component', () => {
40+
it('also has a test', () => {
41+
// This test will run.
42+
});
43+
});
44+
// #enddocregion
45+
46+
// #docregion fit
47+
describe('some component', () => {
48+
fit('has a test', () => {
49+
// This test will run.
50+
});
51+
it('has another test', () => { throw 'This test will not run.'; });
52+
});
53+
// #enddocregion
54+
55+
// #docregion xit
56+
describe('some component', () => {
57+
xit('has a test', () => { throw 'This test will not run.'; });
58+
it('has another test', () => {
59+
// This test will run.
60+
});
61+
});
62+
// #enddocregion
63+
64+
// #docregion beforeEach
65+
describe('some component', () => {
66+
beforeEach(() => { db.connect(); });
67+
it('uses the db', () => {
68+
// Database is connected.
69+
});
70+
});
71+
// #enddocregion
72+
73+
// #docregion beforeEachProviders
74+
describe('some component', () => {
75+
beforeEachProviders(() => [provide(MyService, {useClass: MyMockService})]);
76+
it('uses MyService', inject([MyService], (service) => {
77+
// service is an instance of MyMockService.
78+
}));
79+
});
80+
// #enddocregion
81+
82+
// #docregion afterEach
83+
describe('some component', () => {
84+
afterEach((done) => { db.reset().then((_) => done()); });
85+
it('uses the db', () => {
86+
// This test can leave the database in a dirty state.
87+
// The afterEach will ensure it gets reset.
88+
});
89+
});
90+
// #enddocregion

modules/angular2/platform/browser.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,7 @@ export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CON
6262
*
6363
* We can use this script code:
6464
*
65-
* ```
66-
* @Component({
67-
* selector: 'my-app',
68-
* template: 'Hello {{ name }}!'
69-
* })
70-
* class MyApp {
71-
* name:string;
72-
*
73-
* constructor() {
74-
* this.name = 'World';
75-
* }
76-
* }
77-
*
78-
* main() {
79-
* return bootstrap(MyApp);
80-
* }
81-
* ```
65+
* {@example core/ts/bootstrap/bootstrap.ts region='bootstrap'}
8266
*
8367
* When the app developer invokes `bootstrap()` with the root component `MyApp` as its
8468
* argument, Angular performs the following tasks:

modules/angular2/src/common/forms/validators.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ import * as modelModule from './model';
1313
*
1414
* ### Example
1515
*
16-
* ```typescript
17-
* var providers = [
18-
* new Provider(NG_VALIDATORS, {useValue: myValidator, multi: true})
19-
* ];
16+
* {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'}
2017
* ```
2118
*/
2219
export const NG_VALIDATORS: OpaqueToken = CONST_EXPR(new OpaqueToken("NgValidators"));
20+
21+
/**
22+
* Providers for asynchronous validators to be used for {@link Control}s
23+
* in a form.
24+
*
25+
* Provide this using `multi: true` to add validators.
26+
*
27+
* See {@link NG_VALIDATORS} for more details.
28+
*/
2329
export const NG_ASYNC_VALIDATORS: OpaqueToken = CONST_EXPR(new OpaqueToken("NgAsyncValidators"));
2430

2531
/**

modules/angular2/src/core/application_ref.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,8 @@ export abstract class PlatformRef {
173173
* typical providers, as shown in the example below.
174174
*
175175
* ### Example
176-
* ```
177-
* var myAppProviders = [MyAppService];
178176
*
179-
* platform()
180-
* .application([myAppProviders])
181-
* .bootstrap(MyTopLevelComponent);
182-
* ```
177+
* {@example core/ts/platform/platform.ts region='longform'}
183178
* ### See Also
184179
*
185180
* See the {@link bootstrap} documentation for more details.
@@ -315,11 +310,7 @@ export abstract class ApplicationRef {
315310
* child components under it.
316311
*
317312
* ### Example
318-
* ```
319-
* var app = platform.application([appProviders];
320-
* app.bootstrap(FirstRootComponent);
321-
* app.bootstrap(SecondRootComponent, [provide(OverrideBinding, {useClass: OverriddenBinding})]);
322-
* ```
313+
* {@example core/ts/platform/platform.ts region='longform'}
323314
*/
324315
abstract bootstrap(componentType: Type,
325316
providers?: Array<Type | Provider | any[]>): Promise<ComponentRef>;

modules/angular2/src/core/debug/debug_element.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {ElementRef, ElementRef_} from 'angular2/src/core/linker/element_ref';
1010
* A DebugElement contains information from the Angular compiler about an
1111
* element and provides access to the corresponding ElementInjector and
1212
* underlying DOM Element, as well as a way to query for children.
13+
*
14+
* A DebugElement can be obtained from a {@link ComponentFixture} or
15+
* {@link RootTestComponent}.
1316
*/
1417
export abstract class DebugElement {
1518
get componentInstance(): any { return unimplemented(); };
@@ -156,7 +159,7 @@ export class DebugElement_ extends DebugElement {
156159
}
157160

158161
/**
159-
* Returns a DebugElement for a ElementRef.
162+
* Returns a {@link DebugElement} for an {@link ElementRef}.
160163
*
161164
* @param {ElementRef}: elementRef
162165
* @return {DebugElement}

0 commit comments

Comments
 (0)