简体   繁体   English

Angular JS将许多变量md-autocomplete传递给另一页

[英]Angular JS passing many variable md-autocomplete to another page

i just starting to learn angular JS a month ago. 我一个月前才开始学习有角度的JS。 And found something difficult. 并发现困难。 I have the following plunker http://plnkr.co/edit/nsu6Pj?p=info 我有以下矮人http://plnkr.co/edit/nsu6Pj?p=info

<input id="tags" ng-keyup="complete()" ng-model="data"/>
  selected = {{data}}

As you can see, there is a list of available tags. 如您所见,这里有可用标签的列表。 i want to pass the selected value in the index.html page to next.html page by clicking the button. 我想通过单击按钮将index.html页中的选定值传递给next.html页。

Actually i want pass not just 1 parameter. 实际上,我不仅要传递1个参数。 Just like md-autocomplete in angular material. 就像在角材料中使用md-autocomplete一样。 Here is the image for example parameters i want to pass 这是我要传递的示例参数的图像

I hope you guys can help me :) Thanks. 我希望你们能帮助我:)谢谢。

Well, if you're passing multiple values, you can choose to hold your values in an array or an object. 好吧,如果要传递多个值,则可以选择将值保存在数组或对象中。 I personally would just set your complete function to push the values to an array. 我个人只是将您的完整功能设置为将值推入数组。

Now, as for exchanging data - You have three options that I can think of: 现在,关于交换数据-我想到了三个选择:

  1. create a service that allows controllers to communicate with each other. 创建一个允许控制器相互通信的服务。 You could then use that service to set a variable in one controller (holding your tags) and then use same service in a different controller to get the value. 然后,您可以使用该服务在一个控制器中设置一个变量(保留标签),然后在另一个控制器中使用相同的服务来获取值。

  2. broadcast an event in one controller with $rootScope.$broadcast and then listen to the event with $rootScope.$on 使用$ rootScope。$ broadcast在一个控制器中广播事件,然后使用$ rootScope。$ on收听事件

  3. Save the data to the browser's cookies with angular's $cookieStore. 使用angular的$ cookieStore将数据保存到浏览器的Cookie中。

Now the way your stuff is actually set up you're instantiating a new module and controller in each page so options 1 and 2 are out. 现在,您的东西的实际设置方式是在每个页面中实例化一个新模块和控制器,因此选项1和2消失了。 Here's how I set up saving the values in the cookies. 这是我设置如何在Cookie中保存值的方法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM