This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChangeDetectionStrategy } from '@angular/core'; | |
import { Component } from '@angular/core'; | |
import { BehaviorSubject } from 'rxjs'; | |
@Component({ | |
selector: 'app-container', | |
templateUrl: ` | |
<button (click)="add(4)" class="btn btn-primary">Add Number</button> | |
<app-child [data]="numbers$"></app-child> | |
`, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-counter', | |
template: ` | |
<p> {{res$ | async}}</p> | |
... | |
`, | |
styleUrls: ['./counter.component.scss'], | |
}) | |
export class CounterComponent { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-counter', | |
template: ` | |
... | |
`, | |
styleUrls: ['./counter.component.scss'], | |
providers: [SomeProvider], | |
deps: [SomeDirective, SomePipe, SomeModule] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
const injector = ɵɵdirectiveInject(INJECTOR); | |
ɵrenderComponent(CounterComponent, { host: 'counter-host', injector }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(private injector: Injector) { } | |
ngOnInit() { | |
ɵrenderComponent(CounterComponent, { host: 'counter-host', injector: this.injector }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-counter', | |
template: ` | |
<p>Counter value: {{counter}}</p> | |
<button (click)="plus()" class="btn btn-primary">+</button> | |
<button (click)="reset()" class="btn btn-danger">Reset</button> | |
<button (click)="save()" class="btn btn-success">Save</button> | |
`, | |
styleUrls: ['./counter.component.scss'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class StorageService { | |
constructor(private httpClient: HttpClient) { } | |
saveCounter(counter: number) { | |
return this.httpClient.post('SOME_FAKE_URL', { counter }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-counter', | |
template: ` | |
<p>Counter value: {{counter}}</p> | |
<button (click)="plus()" class="btn btn-primary">+</button> | |
<button (click)="reset()" class="btn btn-danger">Reset</button> | |
<button (click)="save()" class="btn btn-success">Save</button> | |
`, | |
styleUrls: ['./counter.component.scss'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-render-comp', | |
template: `<counter-host></counter-host>`, | |
styleUrls: ['./render-comp.component.scss'], | |
}) | |
export class RenderCompComponent implements OnInit { | |
ngOnInit() { | |
ɵrenderComponent(CounterComponent, { host: 'counter-host' }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-render-comp', | |
template: `<counter-host></counter-host>`, | |
styleUrls: ['./render-comp.component.scss'], | |
}) | |
export class RenderCompComponent implements OnInit { | |
ngOnInit() { | |
ɵrenderComponent(CounterComponent, { host: 'counter-host' }); | |
} |