使用angularjs将表单数据从一个页面发送到另一个页面

时间:2022-04-21 18:50:18

Hello can any one please tell me how to send on form data to another by clicking submit button using angular JS.

您好任何人都可以告诉我如何使用angular JS单击提交按钮将表单数据发送到另一个。

1 个解决方案

#1


4  

There are three ways to do that.

有三种方法可以做到这一点。

  1. If you are using SPA flow for your website, you can make a service for data that are to be shared among pages. Redirection will only change the hash value of URL and landing page will still have those data from service.
  2. 如果您正在为您的网站使用SPA流,则可以为要在页面之间共享的数据提供服务。重定向只会更改URL的哈希值,而着陆页仍然会有来自服务的数据。
  3. Second is to use the hash value for data as lets say that you are redirecting from baseURL/test1 to baseURL/test2 so instead of redirecting to baseURL/test2, you can redirect to baseURL/test2#/data=* , * representing the data. The redirection will still happen but now you can also get the data.
  4. 第二个是使用数据的哈希值,因为我们说你要从baseURL / test1重定向到baseURL / test2,所以你可以重定向到baseURL / test2#/ data = *,*代表数据,而不是重定向到baseURL / test2 。重定向仍将发生,但现在您也可以获取数据。
  5. Third is to use local storage or webSQL ( although limited browser support for webSQL), to save the data and then retrieve back on the next page.
  6. 第三是使用本地存储或webSQL(尽管对webSQL有限的浏览器支持),保存数据然后在下一页上检索。

While I will stick to the SPA flow for my angular website and use a service to pass on the data. There is also a way to assign data in $rootScope but that is just not a good practice to pass on data from one page to another.

虽然我将坚持我的角度网站的SPA流程,并使用服务传递数据。还有一种方法可以在$ rootScope中分配数据,但这不是将数据从一个页面传递到另一个页面的好方法。

#1


4  

There are three ways to do that.

有三种方法可以做到这一点。

  1. If you are using SPA flow for your website, you can make a service for data that are to be shared among pages. Redirection will only change the hash value of URL and landing page will still have those data from service.
  2. 如果您正在为您的网站使用SPA流,则可以为要在页面之间共享的数据提供服务。重定向只会更改URL的哈希值,而着陆页仍然会有来自服务的数据。
  3. Second is to use the hash value for data as lets say that you are redirecting from baseURL/test1 to baseURL/test2 so instead of redirecting to baseURL/test2, you can redirect to baseURL/test2#/data=* , * representing the data. The redirection will still happen but now you can also get the data.
  4. 第二个是使用数据的哈希值,因为我们说你要从baseURL / test1重定向到baseURL / test2,所以你可以重定向到baseURL / test2#/ data = *,*代表数据,而不是重定向到baseURL / test2 。重定向仍将发生,但现在您也可以获取数据。
  5. Third is to use local storage or webSQL ( although limited browser support for webSQL), to save the data and then retrieve back on the next page.
  6. 第三是使用本地存储或webSQL(尽管对webSQL有限的浏览器支持),保存数据然后在下一页上检索。

While I will stick to the SPA flow for my angular website and use a service to pass on the data. There is also a way to assign data in $rootScope but that is just not a good practice to pass on data from one page to another.

虽然我将坚持我的角度网站的SPA流程,并使用服务传递数据。还有一种方法可以在$ rootScope中分配数据,但这不是将数据从一个页面传递到另一个页面的好方法。