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 { Component, OnInit, ViewChild, ElementRef, NgZone, ChangeDetectorRef } from '@angular/core'; | |
@Component({ | |
selector: 'app-animated-div', | |
template: `<div #div></div>`, | |
styleUrls: ['./animated-div.component.scss'] | |
}) | |
export class AnimatedDivComponent implements OnInit { | |
@ViewChild('div', { static: true }) div: ElementRef |
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 AppComponent implements OnInit { | |
constructor(private ngZone: NgZone) {} | |
ngOnInit() { | |
// New async API is not handled by Zone, so you need to | |
// use ngZone.run() to make the asynchronous operation in the angular zone | |
// and trigger change detection automatically. | |
this.ngZone.run(() => { | |
someNewAsyncAPI(() => { | |
// update the data of the component | |
}); |
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
<html> | |
<div id="dataDiv"></div> | |
<button id="btn" (click)="handler()"> ClickMe </button> | |
<script> | |
let count = 0; | |
// initial rendering | |
detectChange(); | |
function renderHTML() { | |
document.getElementById('dataDiv').innerText = count; |
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
let message = "HI"; | |
let sayHi = { | |
say: function() { | |
console.log( message); | |
} | |
}; | |
setTimeout(sayHi.say); | |
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
let sayHi = { | |
message: 'HI', | |
say: function() { | |
console.log(this.message); | |
} | |
}; | |
setTimeout(sayHi.say.bind(sayHi)); |
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
class SayHi { | |
message = 'HI!' | |
say= () => console.log(this.message) | |
}; | |
var sayHi = new SayHi(); | |
setTimeout(sayHi.say); |
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: 'child', | |
template: ` | |
<h1>{{object.name}}</h1> | |
{{runChangeDetection}} | |
`, | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class TooltipComponent { | |
@Input() object; |
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
onClick() { | |
this.object = { | |
name: 'React' | |
} |
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({ | |
template: ` | |
<button (click)="increase()">Click</button> | |
{{count}} | |
`, | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class CounterComponent { | |
count = 0; | |
increase() { |
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({ | |
template: `...`, | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class CounterComponent { | |
count = 0; | |
constructor() { | |
setTimeout(() => this.count ++, 0); |
OlderNewer