Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 95807ff

Browse files
committed
Jesus' edits
1 parent afbe26f commit 95807ff

File tree

6 files changed

+42
-51
lines changed

6 files changed

+42
-51
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// #docplaster
22
// #docregion
33
import { Component } from '@angular/core';
4-
import { SimpleSelectComponent } from './simple-select.component';
54

65
interface Color {
76
hex: string;
@@ -11,9 +10,7 @@ interface Color {
1110
// #docregion metadata
1211
@Component({
1312
selector: 'my-app',
14-
directives: [ SimpleSelectComponent ],
15-
template:
16-
`
13+
template: `
1714
<p>
1815
Selected color: {{ selectedColor?.name || "None selected" }}.
1916
</p>
@@ -25,13 +22,13 @@ interface Color {
2522
</template>
2623
</simple-select>
2724
28-
<simple-select
25+
<simple-select
2926
[items]="colors"
3027
[(value)]="selectedColor"
31-
[template]="externalTemplate">
28+
[template]="itemTemplateRef">
3229
</simple-select>
3330
34-
<template #externalTemplate let-item="item">
31+
<template #itemTemplateRef let-item="item">
3532
<span class="name" [style.color]="item.hex">
3633
{{ item.hex }} &mdash; {{ item.name }}
3734
</span>
@@ -40,11 +37,10 @@ interface Color {
4037
})
4138
// #enddocregion metadata
4239
export class AppComponent {
40+
colors: Color[];
41+
selectedColor: Color;
4342

44-
public colors: Color[];
45-
public selectedColor: Color;
46-
47-
public constructor() {
43+
constructor() {
4844
this.colors = [
4945
{ hex: '#000000', name: 'Black' },
5046
{ hex: '#FFFFFF', name: 'White' },
@@ -54,7 +50,7 @@ export class AppComponent {
5450
{ hex: '#6DC066', name: 'Green' },
5551
{ hex: '#FF00FF', name: 'Magenta' }
5652
];
57-
this.selectedColor = this.colors[ 0 ];
53+
this.selectedColor = this.colors[0];
5854
}
5955

6056
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
import { AppComponent } from './app.component';
5+
import { SimpleSelectComponent } from './simple-select.component';
6+
7+
@NgModule({
8+
imports: [ BrowserModule ],
9+
declarations: [ AppComponent, SimpleSelectComponent ],
10+
bootstrap: [ AppComponent ]
11+
})
12+
export class AppModule {}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
/* tslint:disable */
21
// #docregion
3-
import { bootstrap } from '@angular/platform-browser-dynamic';
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
43

5-
import { AppComponent } from './app.component';
4+
import { AppModule } from './app.module';
65

7-
bootstrap(AppComponent).then(
8-
() => window.console.info('Angular finished bootstrapping your application!'),
9-
(error) => {
10-
console.warn('Angular was not able to bootstrap your application.');
11-
console.error(error);
12-
}
13-
);
6+
platformBrowserDynamic().bootstrapModule(AppModule);

public/docs/_examples/cb-item-template/ts/app/simple-select.component.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ interface ItemContext {
2121
template:
2222
`
2323
<button (click)="toggleItems()" class="select-root">
24-
25-
<template
24+
25+
<template
2626
[ngTemplateOutlet]="itemTemplateRef"
2727
[ngOutletContext]="{ item: value, index: -1 }">
2828
</template>
2929
3030
</button>
31-
31+
3232
<ul *ngIf="isShowingItems" class="select-items">
33-
<li *ngFor="let item of items ; let index = index ;" (click)="selectItem( item )">
34-
35-
<template
33+
<li *ngFor="let item of items ; let index = index" (click)="selectItem(item)">
34+
35+
<template
3636
[ngTemplateOutlet]="itemTemplateRef"
3737
[ngOutletContext]="{ item: item, index: index }">
3838
</template>
@@ -43,20 +43,11 @@ interface ItemContext {
4343
})
4444
// #enddocregion metadata
4545
export class SimpleSelectComponent {
46-
47-
public isShowingItems: boolean;
48-
@Input() public items: any[];
49-
public itemTemplateRef: TemplateRef<ItemContext>;
50-
@Input() public value: any;
51-
@Output() public valueChange: EventEmitter<any>;
52-
53-
constructor() {
54-
this.isShowingItems = false;
55-
this.items = [];
56-
this.itemTemplateRef = null;
57-
this.value = null;
58-
this.valueChange = new EventEmitter();
59-
}
46+
isShowingItems = false;
47+
itemTemplateRef: TemplateRef<ItemContext>;
48+
@Input() items: any[] = [];
49+
@Input() value: any;
50+
@Output() valueChange = new EventEmitter<any>();
6051

6152
// #docregion setters
6253
@Input()
@@ -74,12 +65,12 @@ export class SimpleSelectComponent {
7465
}
7566
// #enddocregion setters
7667

77-
public selectItem(item: any) {
68+
selectItem(item: any): void {
7869
this.valueChange.emit(item);
7970
this.toggleItems();
8071
}
8172

82-
public toggleItems() {
73+
toggleItems(): void {
8374
this.isShowingItems = ! this.isShowingItems;
8475
}
8576

public/docs/_examples/cb-item-template/ts/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
6+
77
<title>
88
Providing An Item Template To A Component
99
</title>
@@ -21,7 +21,6 @@
2121
<script src="systemjs.config.js"></script>
2222
<script>
2323
System.import('app')
24-
.then(function() { console.info('System.js loaded your application module.')})
2524
.catch(function(err){ console.error(err); });
2625
</script>
2726
</head>

public/docs/ts/latest/cookbook/_data.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@
4343
"intro": "Render dynamic forms with FormGroup"
4444
},
4545

46+
"item-template": {
47+
"title": "Item Template",
48+
"intro": "Providing a component with an item template for dynamic rendering."
49+
},
50+
4651
"rc4-to-rc5": {
4752
"title": "RC4 to RC5 Migration",
4853
"intro": "Migrate your RC4 app to RC5 in minutes."
4954
},
5055

51-
"item-template": {
52-
"title": "Item Template",
53-
"intro": "Providing a component with an item template for dynamic rendering."
54-
},
55-
5656
"set-document-title": {
5757
"title": "Set the Document Title",
5858
"intro": "Setting the document or window title using the Title service."

0 commit comments

Comments
 (0)