首页 > 解决方案 > 在选择标签内添加一个额外的按钮作为选项,以便单击该按钮会打开另一个对话框

问题描述

我有一个选择下拉列表,其中显示名称列表(使用 ng-repeat)。如果没有名称,我想显示一个“添加名称”按钮,然后单击我想执行某些功能的按钮。

我正在使用普通的选择标签并使用 ng-repeat 来显示名称列表。

<select ng-model='selectedName' ng-change="onChange()">
    <option ng-repeat='name in names'>{{name}}</option>
    <option ng-if='!names.length'>
        <button ng-click="addName()">Add Name</button>
    </option>

在控制器中:

$scope.names = ['a','b','c','d'];

我希望在单击按钮时它会调用 addName() 函数,但它正在调用 select 标签上的 onChange()。

标签: angularjsselectbutton

解决方案


元素唯一允许的内容<option>是文本。1

Content categories: None.
Permitted content:  Text, possibly with escaped characters (like &eacute;).
Tag omission:       The start tag is mandatory. The end tag is optional if this element is immediately followed by another <option> element or an <optgroup>, or if the parent element has no more content.
Permitted parents:  A <select>, an <optgroup> or a <datalist> element.
Permitted ARIA roles:   None
DOM interface:      HTMLOptionElement 

有关详细信息,请参阅


推荐阅读