angularjs multiple controllers on one page

后端 未结 5 960
甜味超标
甜味超标 2021-02-12 15:50

I have a page with multiple controllers, one of the controller is being used in 2 different divs within the same page. I am not sure if it is a scope issue or I just miss someth

5条回答
  •  忘了有多久
    2021-02-12 16:29

    You already got your answer i guess, but for those who will come next here is some tips ^^ (hope it will hep):

    • ng-controller="myCtrl" will set a new instance of the "myCtrl" controller, with i'ts own scope

    • The used scope will be the one of the firt div's controller it means that if you have something like:

             
    some text
    - so this is a subdiv .
  • Subdiv1 will have the same scope as maindiv
  • But Subdiv2 will have it's own instance of the myCtrl controller's scope.
  • In a global way, Subdiv2's scope should have erited is data from the maindiv's scope.

Thats just a few easy tips and you will find more usefull ones on SO, or google, but anyway, if it can help some of you it will be cool.

提交回复
热议问题