问题
I have a ViewBag data from the controller that I get in the View. However, my view is made of multiple components and a component (Which is a html template and relevant JavaScript), has a placeholder for this data where I need to display this data.
How would I pass this @ViewBag.Data to the placeholder in another view (Template here). ?
Or, would it be easy to consider passing the data from Controller to another view?
Please help me with a sample snippet
回答1:
If I understood correctly you can do this by using the same controller for your second view, like writing ng-controller="SameController" or creating an angular service or factory and sharing your data between two different controllers that each one serves a specific template/view.
来源:https://stackoverflow.com/questions/37990874/how-to-pass-viewbag-data-from-view-to-another-component-template-that-i-call-in