如何从视图数据传递给viewbag,我在此视图调用另一个组件模板 [英] how to pass viewbag data from view to another component template that I call in this view

查看:252
本文介绍了如何从视图数据传递给viewbag,我在此视图调用另一个组件模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从控制器 ViewBag 数据,我在查看得到。然而,我的观点是由多个组件和部件(这是一个 HTML 模板和相关的的JavaScript ),具有对于这个数据,我需要显示此数据的占位符。

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.

我将如何传递这个 @ ViewBag.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?

请帮我一个示例代码段

推荐答案

如果我理解正确的话,你可以用相同的控制器为你的第二个观点,就像写 NG-控制器=SameController这样做或创建一个角的服务或工厂和两个不同的控制器,每一个都提供特定的模板/视图。之间共享数据。

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.

这篇关于如何从视图数据传递给viewbag,我在此视图调用另一个组件模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆