在Angularjs中将选择ng选项转换为单选按钮ng-repeat

时间:2016-09-30 10:20:37

标签: javascript angularjs

我有一个从我想要转换为重复单选按钮的服务中提取的选择下拉列表。

这是工作代码作为下拉列表:

<select id="selectTitle" name="selectTitle" class="form-control" ng-model="selectTitle" ng-options="item.text for item in items track by item.value">
       <option value='' disabled selected>Select One...</option>

然后认为用以下内容替换是一项简单的任务,但遗憾的是没有。嗯很奇怪。

 <label ng-repeat="item.text for item in items track by item.value">
     <input type="radio" name="pageNumber" ng-model="selectTitle" /> {{text}}

所以我现在为此创建了一个Plunker,我仍然遇到问题,我已经让它显示某个级别,但只想要选项01,选项02显示为标签。

非常感谢任何帮助。

感谢。

plnkr.co/edit/xNVVFohA6DeU9nCgi7fQ?p=preview

3 个答案:

答案 0 :(得分:1)

您无法在下拉菜单中使用ng-options语法作为单选按钮中的ng-repeat语法, 试试这个:

import webbrowser
import random
sol1 = ("Check if there is lint in the charging ports. This can be removed\ncarefully with a toothpick or similar implement")
sol2 = ("Turn on assistive touch if you have an iphone (settings > general >\naccessability > assistive touch until you go to a shop to get them replaced If  you use android, download 'button savior' from the google play store")
sol3 = ("Do a hard reset - hold down the power and home buttons until the screen\nturns off and keep them held down until the screen turns on again ")
sol4 = ("Restore the phone to factory settings and set it up as new")
sol5 = ("You need a screen replacement.")
sol6 = ("You may need to replace the battery.")
sol7 = ("You dont need to do anything. Your phone doesnt have any problems.")
sol8 = ("Please update your phone software.")
sol9 = ("Contact apple for support")
sol10 = ("Take the phone and put it in a bag of rice for\n24-36 hours to let the rice absorb the water.")

q1 = str(input("Is your phone charging correctly? Y/N >> "))
for i in range(1):
    q1 = str.lower(q1)
if q1 == "n":
    print(sol1)

elif q1 == "y":
    q2 = str(input("Is your phone water damaged? Y/N >> "))
    for i in range(1):
        q2 = str.lower(q2)
if q2 == "y":
    print(sol10)

elif q2 == "n":
    q3 = str(input("Is the screen cracked or badly scratched? Y/N >> "))
    for i in range(1):
        q3 = str.lower(q3)
if q3 == "y":
    print(sol5)

elif q3 == "n":
    q4 = str(input("Is the phone working slowly and crashing? Y/N >> "))
    for i in range(1):
        q4 = str.lower(q4)
if q4 == "y":
    print(sol3)

elif q4 == "n":
    q5 = str(input("Do you wish to remove data from the phone? Y/N >> "))
    for i in range(1):
         q5 = str.lower(q5)
if q5 == "y":
    print(sol4)

elif q5 == "n":
    q6 = str(input("Does the phone work without issues? Y/N >> "))
    for i in range(1):
        q6 = str.lower(q6)
if q6 == "y":
    print(sol7)

elif q6 == "n":
    q7 = str(input("Are you running the lastest software version? Y/N >> "))
    for i in range(1):
        q7 = str.lower(q7)
if q7 == "n":
    print(sol8)

elif q7 == "y":
    q8 = str(input("Are the buttons producing accurate responses Y/N >> "))
    for i in range(1):
        q8 = str.lower(q8)
if q8 == "n":
     print(sol2)

elif q8 == "y":
    q9 = str(input("Is your phone battery draining and dying early? Y/N >> "))
    for i in range(1):
        q9 = str.lower(q9)
if q9 == "y":
    print(sol6)

elif q9 == "n":
    q10 = str(input("Does the phone turn on, even if it has been charged with a working charger? Y/N >> "))
    for i in range(1):
        q10 = str.lower(q10)
if q10 == "y":
     print(sol9)

elif q10 == "n":
    q11 = str(input("Would you like to visit the apple support site?: yes/no Y/N >> "))
    for i in range(1):
        q11 = str.lower(q11)
if q11 == "y":
    webbrowser.open("https://support.apple.com/en-gb")

elif q11 == "n":
    q12 = str(input("Would you like to visit the genius bar booking site?:  Y/N >> "))
    for i in range(1):
        q12 = str.lower(q12)

if q12 == "y":
    webbrowser.open("https://getsupport.apple.com/")
else:
    print()

答案 1 :(得分:1)

ng-repeat语法与ng-options

不同
<label ng-repeat="item in items">
    <input type="radio" name="pageNumber" ng-model="selectTitle" /> {{item.text}}
</label>

答案 2 :(得分:0)

您还需要一个值,例如

 <input type="radio" name="pageNumber" ng-model="selectTitle" value="{{item.value}}" />