$rootScope hauv AngularJS yog dab tsi?
$rootScope hauv AngularJS yog dab tsi?

Video: $rootScope hauv AngularJS yog dab tsi?

Video: $rootScope hauv AngularJS yog dab tsi?
Video: Difference between $scope and $rootScope 2024, Kaum ib hlis
Anonim

Txhua daim ntawv thov muaj $ rootScope uas yog qhov tsim los ntawm HTML keeb uas muaj cov lus qhia ng-app. Cov rootScope muaj nyob rau hauv tag nrho daim ntawv thov. Yog tias ib qho kev sib txawv muaj tib lub npe nyob rau hauv ob qho tib si tam sim no thiab hauv rootScope , daim ntawv thov siv ib qho hauv qhov tam sim no.

Ib yam li ntawd, tib neeg nug, dab tsi yog emit hauv AngularJS?

$broadcast() as well as $ tawm () tso cai rau koj tsa ib qho kev tshwm sim hauv koj AngularJS daim ntawv thov. Qhov txawv ntawm $broadcast() thiab $ tawm () yog tias tus qub xa cov xwm txheej los ntawm tus tswj tam sim no mus rau tag nrho nws cov me nyuam tswj. Qhov ntawd txhais tau tias $ tshaj tawm () xa ib qho qis qis los ntawm niam txiv mus rau tus tswj me nyuam.

Ib sab saum toj, dab tsi yog $ rhuav tshem hauv AngularJS? AngularJS : Mloog $ ua kom puas . Angular yuav tshaj tawm ib qho $ ua kom puas kev tshwm sim ua ntej rhuav tshem ib txoj haujlwm thiab tshem tawm ntawm nws niam nws txiv. Kev mloog rau qhov xwm txheej no yog qhov tseem ceeb rau kev ntxuav cov dej num thiab cov peev txheej uas txwv tsis pub yuav txuas ntxiv zom cov cim xeeb lossis CPU.

Hauv qhov no, qhov sib txawv ntawm cov peev txheej thiab lub hauv pausScope hauv AngularJS yog dab tsi?

$ rootScope hais txog ib yam khoom uas siv tau los ntawm txhua qhov chaw ntawm daim ntawv thov peb tuaj yeem hais tias nws yog lub ntiaj teb thaj tsam ntawm variable. $ rootScope yog niam txiv khoom ntawm txhua qhov whereas $ thaj tsam cov khoom angular tsim hauv a lub vev xaib. $ thaj tsam yog tsim nrog ng-controller thaum $ keeb kwm yog tsim nrog ng-app.

Scope emit yog dab tsi?

Qhov $ thaj tsam muaj lub luag haujlwm hu ua $ tawm () uas yog siv los tawm ib qho kev tshwm sim upwards nyob rau hauv lub thaj tsam hierarchy. Cov xwm txheej lub neej voj voog pib nrog rau thaj tsam koj $ tawm () tau raug hu thiab raug xa mus rau sab saud thaj tsam hierarchy rau tag nrho cov sau npe mloog.

Pom zoo: