-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
45 lines (40 loc) · 929 Bytes
/
index.ts
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
import {Component, Input, ɵrenderComponent as renderComponent, Pipe, ɵmarkDirty as markDirty} from '@angular/core';
import '@angular/compiler';
@Component({
selector: 'zippy',
template: `
<button (click)="toggle()">
{{title}}
</button>
<div [hidden]="!show">
<ng-content></ng-content>
</div>
`,
})
class ChildComponent {
@Input() title: string;
show = false;
toggle() {
this.show = !this.show;
markDirty(this);
}
}
@Pipe({ name: 'capitalize' })
class CapitalizePipe {
transform(str: string) {
return str
.split(' ')
.filter(s => !!s)
.map(s => s[0].toUpperCase() + s.slice(1, s.length))
.join(' ');
}
}
@Component({
selector: 'app-cmp',
template: '<zippy title="Toggle">{{ label | capitalize }}</zippy>',
deps: [ChildComponent, CapitalizePipe]
})
class AppComponent {
label = 'hello world';
}
renderComponent(AppComponent);