docs(core): Myriad of documentation changes including lots of new example code.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import {Inject, Injector, forwardRef, resolveForwardRef, ForwardRefFn} from 'angular2/core';
|
||||
|
||||
// #docregion forward_ref_fn
|
||||
var ref = forwardRef(() => Lock);
|
||||
// #enddocregion
|
||||
|
||||
// #docregion forward_ref
|
||||
class Door {
|
||||
lock: Lock;
|
||||
constructor(@Inject(forwardRef(() => Lock)) lock: Lock) { this.lock = lock; }
|
||||
}
|
||||
|
||||
// Only at this point Lock is defined.
|
||||
class Lock {}
|
||||
|
||||
var injector = Injector.resolveAndCreate([Door, Lock]);
|
||||
var door = injector.get(Door);
|
||||
expect(door instanceof Door).toBe(true);
|
||||
expect(door.lock instanceof Lock).toBe(true);
|
||||
// #enddocregion
|
||||
|
||||
// #docregion resolve_forward_ref
|
||||
var ref = forwardRef(() => "refValue");
|
||||
expect(resolveForwardRef(ref)).toEqual("refValue");
|
||||
expect(resolveForwardRef("regularValue")).toEqual("regularValue");
|
||||
// #enddocregion
|
||||
@@ -0,0 +1,10 @@
|
||||
import {bootstrap} from 'angular2/bootstrap';
|
||||
import {NG_VALIDATORS} from 'angular2/common';
|
||||
import {Provider} from 'angular2/core';
|
||||
|
||||
let MyApp = null;
|
||||
let myValidator = null;
|
||||
|
||||
// #docregion ng_validators
|
||||
bootstrap(MyApp, [new Provider(NG_VALIDATORS, {useValue: myValidator, multi: true})]);
|
||||
// #enddocregion
|
||||
@@ -0,0 +1,13 @@
|
||||
import {Component} from 'angular2/core';
|
||||
import {bootstrap} from 'angular2/platform/browser';
|
||||
|
||||
// #docregion bootstrap
|
||||
@Component({selector: 'my-app', template: 'Hello {{ name }}!'})
|
||||
class MyApp {
|
||||
name: string = 'World';
|
||||
}
|
||||
|
||||
function main() {
|
||||
return bootstrap(MyApp);
|
||||
}
|
||||
// #enddocregion
|
||||
@@ -0,0 +1,43 @@
|
||||
import {Component, Attribute, Directive, Pipe} from 'angular2/core';
|
||||
|
||||
var CustomDirective;
|
||||
|
||||
// #docregion component
|
||||
@Component({selector: 'greet', template: 'Hello {{name}}!', directives: [CustomDirective]})
|
||||
class Greet {
|
||||
name: string = 'World';
|
||||
}
|
||||
// #enddocregion
|
||||
|
||||
// #docregion attributeFactory
|
||||
@Component({selector: 'page', template: 'Title: {{title}}'})
|
||||
class Page {
|
||||
title: string;
|
||||
constructor(@Attribute('title') title: string) { this.title = title; }
|
||||
}
|
||||
// #enddocregion
|
||||
|
||||
// #docregion attributeMetadata
|
||||
@Directive({selector: 'input'})
|
||||
class InputAttrDirective {
|
||||
constructor(@Attribute('type') type) {
|
||||
// type would be 'text' in this example
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
||||
|
||||
// #docregion directive
|
||||
@Directive({selector: 'input'})
|
||||
class InputDirective {
|
||||
constructor() {
|
||||
// Add some logic.
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
||||
|
||||
// #docregion pipe
|
||||
@Pipe({name: 'lowercase'})
|
||||
class Lowercase {
|
||||
transform(v, args) { return v.toLowerCase(); }
|
||||
}
|
||||
// #enddocregion
|
||||
@@ -0,0 +1,13 @@
|
||||
import {Component, platform} from 'angular2/core';
|
||||
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
|
||||
|
||||
var appProviders: any[] = [];
|
||||
|
||||
// #docregion longform
|
||||
@Component({selector: 'my-app', template: 'Hello World'})
|
||||
class MyApp {
|
||||
}
|
||||
|
||||
var app = platform(BROWSER_PROVIDERS).application([BROWSER_APP_PROVIDERS, appProviders]);
|
||||
app.bootstrap(MyApp);
|
||||
// #enddocregion
|
||||
Reference in New Issue
Block a user