Skip to content

Instantly share code, notes, and snippets.

@AregSargsyan
AregSargsyan / ngAfterViewInitchangedetectorref.ts
Created June 7, 2020 12:24
ngAfterViewInit with changedetectorref
import { Component, ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'app-child',
template: `<span>{{count}}</span>`,
})
export class ChildComponent {
count = 0;
@AregSargsyan
AregSargsyan / setTimeOut.ts
Created June 7, 2020 12:16
ngAfterViewInit with setTimeOut
import { Component } from '@angular/core';
@Component({
selector: 'app-child',
template: `<span>{{count}}</span>`,
})
export class ChildComponent {
count = 0;
@AregSargsyan
AregSargsyan / ngAfterViewInit
Created June 6, 2020 14:44
ExpressionChangedAfterItHasBeenCheckedError
import { Component } from '@angular/core';
@Component({
selector: 'app-child',
template: `<span>{{count}}</span>`,
})
export class ChildComponent {
count = 0;
@AregSargsyan
AregSargsyan / onInit.ts
Created June 6, 2020 14:41
ExpressionChangedAfterItHasBeenCheckedError
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-child',
template: `<span>{{count}}</span>`,
})
export class ChildComponent implements OnInit {
count = 0;
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map, } from 'rxjs/operators';
@Component({
selector: 'app-b',
template: `<img [src]="user$|async">`,
changeDetection: ChangeDetectionStrategy.OnPush
})
import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
@Component({
template: `...`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CounterComponent {
count = 0;
constructor(private cd: ChangeDetectorRef) {
@AregSargsyan
AregSargsyan / atherEvents.ts
Last active June 1, 2020 12:58
these event will not trigger change detection
@Component({
template: `...`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CounterComponent {
count = 0;
constructor() {
setTimeout(() => this.count ++, 0);
@AregSargsyan
AregSargsyan / click.ts
Created May 30, 2020 17:21
click event onpush
@Component({
template: `
<button (click)="increase()">Click</button>
{{count}}
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CounterComponent {
count = 0;
increase() {
onClick() {
this.object = {
name: 'React'
}
@AregSargsyan
AregSargsyan / input.ts
Created May 30, 2020 13:01
OnPush works when input referense changed
@Component({
selector: 'child',
template: `
<h1>{{object.name}}</h1>
{{runChangeDetection}}
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TooltipComponent {
@Input() object;