Telegram Group & Telegram Channel
Использование ChangeDetectorRef.detach() в Angular

Метод ChangeDetectorRef.detach() позволяет отключить компонент от системы обнаружения изменений. Это полезно, если компонент не должен отслеживать изменения постоянно. После вызова detach() Angular перестанет проверять компонент и его потомков на изменения, пока вы не вызовете обновление вручную через detectChanges().

Пример:
import { ChangeDetectorRef, Component } from '@angular/core';

@Component({
selector: 'app-performance',
template: `<div>{{ counter }}</div>`
})
export class PerformanceComponent {
counter = 0;

constructor(private cdr: ChangeDetectorRef) {}

ngOnInit() {
this.cdr.detach(); // Отключаем отслеживание изменений
setInterval(() => {
this.counter++; // Обновляем данные
this.cdr.detectChanges(); // Вручную запускаем проверку изменений
}, 1000);
}
}

В этом примере ChangeDetectorRef.detach() отключает систему обнаружения изменений, а вызов detectChanges() вручную обновляет интерфейс.

👉 @sWebDev
👍6



tg-me.com/sWebDev/3497
Create:
Last Update:

Использование ChangeDetectorRef.detach() в Angular

Метод ChangeDetectorRef.detach() позволяет отключить компонент от системы обнаружения изменений. Это полезно, если компонент не должен отслеживать изменения постоянно. После вызова detach() Angular перестанет проверять компонент и его потомков на изменения, пока вы не вызовете обновление вручную через detectChanges().

Пример:

import { ChangeDetectorRef, Component } from '@angular/core';

@Component({
selector: 'app-performance',
template: `<div>{{ counter }}</div>`
})
export class PerformanceComponent {
counter = 0;

constructor(private cdr: ChangeDetectorRef) {}

ngOnInit() {
this.cdr.detach(); // Отключаем отслеживание изменений
setInterval(() => {
this.counter++; // Обновляем данные
this.cdr.detectChanges(); // Вручную запускаем проверку изменений
}, 1000);
}
}

В этом примере ChangeDetectorRef.detach() отключает систему обнаружения изменений, а вызов detectChanges() вручную обновляет интерфейс.

👉 @sWebDev

BY Frontender Libs - обзор библиотек JS / CSS




Share with your friend now:
tg-me.com/sWebDev/3497

View MORE
Open in Telegram


Frontender Libs обзор библиотек JS CSS Telegram | DID YOU KNOW?

Date: |

That growth environment will include rising inflation and interest rates. Those upward shifts naturally accompany healthy growth periods as the demand for resources, products and services rise. Importantly, the Federal Reserve has laid out the rationale for not interfering with that natural growth transition.It's not exactly a fad, but there is a widespread willingness to pay up for a growth story. Classic fundamental analysis takes a back seat. Even negative earnings are ignored. In fact, positive earnings seem to be a limiting measure, producing the question, "Is that all you've got?" The preference is a vision of untold riches when the exciting story plays out as expected.

Telegram Gives Up On Crypto Blockchain Project

Durov said on his Telegram channel today that the two and a half year blockchain and crypto project has been put to sleep. Ironically, after leaving Russia because the government wanted his encryption keys to his social media firm, Durov’s cryptocurrency idea lost steam because of a U.S. court. “The technology we created allowed for an open, free, decentralized exchange of value and ideas. TON had the potential to revolutionize how people store and transfer funds and information,” he wrote on his channel. “Unfortunately, a U.S. court stopped TON from happening.”

Frontender Libs обзор библиотек JS CSS from us


Telegram Frontender Libs - обзор библиотек JS / CSS
FROM USA