Change Detection txhais tau tias hloov DOM thaum twg cov ntaub ntawv hloov pauv. Angular muab ob lub tswv yim rau Kev Tshawb Fawb Hloov. Hauv nws lub tswv yim zoo, thaum twg cov ntaub ntawv hloov pauv lossis hloov pauv, Angular yuav khiav qhov hloov pauv kom hloov kho DOM.
Angular kuaj pom qhov hloov pauv li cas?
Txhawm rau khiav lub ntsuas qhov hloov pauv manually:
- Txhaj Tshuaj Tiv Thaiv Kev Tiv Thaiv Kev Pabcuam hauv kev tivthaiv.
- Siv markForCheck nyob rau hauv subscription method qhia Angular xyuas cov khoom nyob rau hauv lub sij hawm tom ntej hloov detectors khiav.
- Nyob rau ngOnDestroy lub neej voj voog nuv, unsubscribe from the observable.
Dab tsi yog qhov hloov pauv kev tshawb nrhiav lub voj voog hauv Angular?
Thaum hloov pauv kev tshawb pom Angular khiav dhau ntawm kev khi, ntsuas cov lus qhia, piv rau cov nqi dhau los thiab hloov kho DOM yog tias tsim nyog. Tom qab txhua lub voj voog tshawb pom kev hloov pauv, Angular sau ib daim tshev los xyuas kom meej tias lub xeev cov khoom nyob hauv sync nrog cov neeg siv interface.
Angular onPush hloov nrhiav pom yog dab tsi?
Lub tswv yim OnPush hloov Angular qhov kev hloov pauv tus cwj pwm hauv ib txoj hauv kev zoo ib yam li kev tshem tawm ib feem. Qhov kev hloov pauv tsis ua haujlwm rau txhua qhov txuas ntxiv lawm. Angular hloov mloog rau cov kev hloov pauv tshwj xeebthiab tsuas yog khiav qhov kev hloov pauv ntawm tus ntoo cuam tshuam rau cov khoom ntawd.
Txoj kev tshawb nrhiav kev hloov pauv yog dab tsi?
Lub hauv paus txheej txheem ntawm kev kuaj pom kev hloov pauv yog rauua cov tshev tawm tsam ob lub xeev, ib qho yog lub xeev tam sim no, lwm lub xeev yog lub xeev tshiab. Yog tias ib lub xeev no txawv ntawm lwm qhov, ces ib yam dab tsi tau hloov, txhais tau tias peb yuav tsum tau hloov kho (lossis rov ua dua) qhov kev pom.