This file contains hidden or 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 { Component } from '@angular/core'; | |
| @Component({ | |
| selector: 'app-todos', | |
| template: ` | |
| <app-todo *ngFor="let todo of todos" [todo]="todo"></app-todo> | |
| ` | |
| }) | |
| export class TodosComponent { | |
| public todos: Todo[] = []; |
This file contains hidden or 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 { Component, ChangeDetectionStrategy, Input, ElementRef } from '@angular/core'; | |
| @Component({ | |
| selector: 'app-calendar', | |
| template: ` | |
| <app-events (chooseEvent)="chooseEvent($event.detail)"></app-events> | |
| `, | |
| changeDetection: ChangeDetectionStrategy.OnPush | |
| }) | |
| export class CalendarComponent { |
This file contains hidden or 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
| const event = new CustomEvent('chooseEvent', { | |
| detail: this.event, | |
| bubbles: true | |
| }); | |
| this.host.nativeElement.dispatchEvent(event); |
This file contains hidden or 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 { Component, ChangeDetectionStrategy, Input, ElementRef } from '@angular/core'; | |
| @Component({ | |
| selector: 'app-button', | |
| templateUrl: './button.component.html', | |
| styleUrls: ['./button.component.scss'], | |
| changeDetection: ChangeDetectionStrategy.OnPush | |
| }) | |
| export class ButtonComponent { | |
| @Input() |
This file contains hidden or 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 { Component, OnInit, ViewChild, ElementRef, NgZone } from '@angular/core'; | |
| import * as Chart from 'chart.js'; | |
| @Component({ | |
| selector: 'app-line-chart', | |
| template: ` | |
| <canvas #canvas></canvas> | |
| ` | |
| }) |
This file contains hidden or 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 { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; | |
| import * as Chart from 'chart.js'; | |
| @Component({ | |
| selector: 'app-line-chart', | |
| template: ` | |
| <canvas #canvas></canvas> | |
| ` | |
| }) |
This file contains hidden or 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
| this.todosService.getTodos().pipe( | |
| detectChanges(this.ref) | |
| ).subscribe((todos) => { | |
| this.todos = todos; | |
| }); |
This file contains hidden or 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 function detectChanges<T>(ref: ChangeDetectorRef) { | |
| return finalize<T>(() => !(ref as ViewRef).destroyed && ref.detectChanges()); | |
| } |