角得到选定的选项值,并插入链接 [英] angular get selected option value and insert into link

查看:120
本文介绍了角得到选定的选项值,并插入链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过在下拉列表中选择的选项来填充的链接。我不知道我怎么会从大约选项获得的价值,而不是把它重复。

I'm trying to populate a link via a selected option in a dropdown. I don't know how I would get the value from the about option and not have it repeat.

<div ng-app="" ng-init="horsepower=[
{hp:'15',value:'https://www.compressorworld.com/15-hp-rotary-screw-air-compressor-system-230-3-60-total-air-system.html'},
{hp:'20',value:'https://www.compressorworld.com/20-hp-rotary-screw-air-compressors-complete-air-system-lifetime-airend-warranty.html'}]">


<select>
  <option ng-repeat="x in horsepower" value="{{ x.value}}" ng-model="hp">{{ x.hp}}</option>
</select>
<br/><br/>
<!-- get the selected value of select -->
<a ng-href="{{}}">
buy
</a>

</div>

https://jsfiddle.net/blynn17/171g1x2z/1/

推荐答案

这是更好地使用 NG-选项选择标记并使用 NG-模型调用在的href选定值

It's better to use ng-options in select tag and use the ng-model for calling the selected value in your href

&LT;选择NG选项=x作为马力x.hp对于xVALUE ={{x.value}}NG模型=惠普&GT;

示范
https://jsfiddle.net/heshamElghndour/bhedvue7/

这篇关于角得到选定的选项值,并插入链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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