简体   繁体   English

如何将json对象从一页传递到另一页

[英]How can I pass json object from one page to another page

I'm trying to pass a json object just after redirecting to another page, The problem is when I use $scope.data in order to save client, the problem is that after making the redirection the $scope.data is empty again 我试图在重定向到另一个页面之后传递一个json对象,问题是当我使用$ scope.data来保存客户端时,问题是在进行重定向之后,$ scope.data再次为空

testProjectApp.controller('ClientController', 
 function EventController($scope, clientList, $window, updateClient){


    $scope.editClient=function(client){
        $scope.data=client;
        $window.location.href = 'ClientDetails.html";
    }

the controller is working on two pages 控制器在两页上工作

It depends on if you only want to use angular specific APIs or general methods are also acceptable. 这取决于您是否只想使用特定于角度的API或可接受的常规方法。 Consider the followings, which one better fits your situation, you may need to serialize/de-serialize the json object: 考虑以下内容,它更适合您的情况,您可能需要序列化/反序列化json对象:

Some options: 一些选项:

  1. Cookies 饼干
  2. Session Storage 会话存储
  3. Local Storage 本地存储
  4. Use Url to pass the parameters 使用网址传递参数
  5. If it is a single page application, then you can just set it to a variable in a Service, and inject that service the controllers need the var. 如果它是单页应用程序,则可以将其设置为Service中的变量,然后注入该服务,控制器需要var。 Basically a get , set 基本上是getset

It would be a good idea to figure out the size of the json, and are there any limits and constraints first, then choose the suitable method. 弄清json的大小是一个好主意,首先要有任何限制和约束,然后选择合适的方法。

Angular is used for SPA's - single paged applications. Angular用于SPA-单页应用程序。 As soon as you redirect to another page, a new scope is created. 一旦您重定向到另一个页面,就会创建一个新的作用域。 I used local storage - here I asked and answered my question in reference to it - AngularJS help sharing data between controllers using $broadcast 我使用了本地存储-在这里我参考并询问了我的问题-AngularJS使用$ broadcast帮助在控制器之间共享数据

So to be honest, this is a duplicate. 老实说,这是重复的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将变量从一页传递到另一页? - How can i pass a variable from one page to another? 如何使用javascript将值从一个html页面传递到另一个html页面 - How can I pass values from one html page to another html page using javascript 如何在 ReactJS 中将值或字段从一页传递到另一页? - How can I pass values or fields from one page to another page in ReactJS? 如何将json值从一页传递到另一页(需要帮助) - how to pass json value from one page to another (Help needed) 如何将javascript变量/对象从一页传递到另一页? - How to pass javascript variable/object from one page to another? 下一个 js 在以编程方式导航时将 JSON object 从一页传递到另一页道具 - Next js pass JSON object from one page to another page props when navigating programmatically 如何将变量从一页上的输入框传递到另一页上,并使用此信息在第2页上执行搜索? - how can I pass a variable from an input box on one page to another page and use this info to perform a search on page 2? 传递JSON对象到另一个页面 - Pass JSON Object to another page 如何在没有PHP的情况下用PHP和Javascript将数据从一页传递到另一页? - How can I pass data from one page to another in PHP and Javascript without from? 如何将一个JSP的输入类型值或ID传递给另一个JSP页面 - How can I pass input type value or id from one jsp to another jsp page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM