This repository was archived by the owner on Dec 4, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 862
Expand file tree
/
Copy pathapp.component.ts
More file actions
56 lines (49 loc) · 1.33 KB
/
app.component.ts
File metadata and controls
56 lines (49 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// #docplaster
// #docregion
import { Component } from '@angular/core';
interface Color {
hex: string;
name: string;
}
// #docregion metadata
@Component({
selector: 'my-app',
template: `
<p>
Selected color: {{ selectedColor?.name || "None selected" }}.
</p>
<simple-select [items]="colors" [(value)]="selectedColor">
<template let-item="item">
<span class="swatch" [style.backgroundColor]="item.hex"></span>
<span class="name">{{ item.hex }} — {{ item.name }}</span>
</template>
</simple-select>
<simple-select
[items]="colors"
[(value)]="selectedColor"
[template]="itemTemplateRef">
</simple-select>
<template #itemTemplateRef let-item="item">
<span class="name" [style.color]="item.hex">
{{ item.hex }} — {{ item.name }}
</span>
</template>
`
})
// #enddocregion metadata
export class AppComponent {
colors: Color[];
selectedColor: Color;
constructor() {
this.colors = [
{ hex: '#000000', name: 'Black' },
{ hex: '#FFFFFF', name: 'White' },
{ hex: '#FFD700', name: 'Gold' },
{ hex: '#7FFFD4', name: 'Aquamarine' },
{ hex: '#800080', name: 'Purple' },
{ hex: '#6DC066', name: 'Green' },
{ hex: '#FF00FF', name: 'Magenta' }
];
this.selectedColor = this.colors[0];
}
}