-3

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

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
Jasmine
  • 5,186
  • 16
  • 62
  • 114
  • Could you please provide some code to help better understand the question? – afnpires Jun 23 '16 at 11:57
  • Please include a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Please also read [How do I ask a Good Question](http://stackoverflow.com/help/how-to-ask). Make sure that your questions are specific and not overly broad. – Igor Jun 23 '16 at 11:57

1 Answers1

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.

Cosmin
  • 147
  • 7
  • Cosmin, thank you, but how to implement it? I am new to angular, please help me with a sample code. Also, it should be a good design approach to do the way you advise? – Jasmine Jun 24 '16 at 03:50
  • I just realized, I can not use same controller as we have every module, every controller tied up independently for every view and templates – Jasmine Jun 24 '16 at 03:51
  • I am calling one other template from one of the other template view and hence this problem – Jasmine Jun 24 '16 at 03:51
  • @Learner I was referring with sharing data to something like this: [link](http://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers) – Cosmin Jun 24 '16 at 03:58
  • Cosmin, thank you so much, my Lead came and helped me quick, in the project method that we follow. He did it in just within a minute. Thank you so much :) Actually a whole hierachy was involved, but just a field passing data across :) I am new to angular :) – Jasmine Jun 24 '16 at 04:20
  • I gave you a up vote and marked as you were happy to help me – Jasmine Jun 24 '16 at 04:21