javascript - angularjs ui-router How to notify child pages of data changes in the parent page
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-07-04 13:44:45
0
2
1057

Parent page nested sub-page (ui-view also has ui-view inside)

The subpage is written using component, so it cannot inherit the scope of the parent page

Now the parent transfers data to the child by passing parameters $state.go('parent.child', {data: $scope.data})

But if the parent's data is modified, the child page will not know it and it will remain the same.

Is there any way to notify the data modification of the parent page to the child page, or other methods of passing parameters?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
Ty80

Parent scope$broadcastchild page can receive it, child page scope$emitparent page can receive it

世界只因有你

This should be regarded as a data sharing problem between page components. The solutions I can think of are as follows:

  • Borrowing the internal event mechanism of Angular, the child page subscribes to the events published by the parent page to make some changes, and vice versa.

  • Implement a common service to store shared data and inject it into the components of the two pages respectively

  • Use a third-party state hosting container, such as the famous redux, and use ng-redux for adaptation. The two pages change the state stored in the state container by calling action

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!