scope and controller instantiation with ui router

后端 未结 3 1505
忘掉有多难
忘掉有多难 2020-12-01 06:23

I am confused about when controllers get instantiated. Also, how do controllers gets instantiated when nesting states. I might be confused how scope gets attached to view an

3条回答
  •  天涯浪人
    2020-12-01 07:14

    Controllers get instantiated when the corresponding views are loaded for the first time.

    For example if you have 3 tabs associated with 3 controllers - then the controller associated with the default view instantiates First. Next when you load the other views the associated controllers also get instantiated.

    But interestingly, once a view is loaded in the DOM - it is cached by-default. When a view is navigated away from, its element is left in the DOM, and its scope is disconnected from the $watch cycle. When navigating to a view that is already cached, its scope is then reconnected, and the existing element that was left in the DOM becomes the active view.

提交回复
热议问题