angularjs - 在选择标签内添加一个额外的按钮作为选项,以便单击该按钮会打开另一个对话框
问题描述
我有一个选择下拉列表,其中显示名称列表(使用 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()。
解决方案
元素唯一允许的内容<option>
是文本。1
Content categories: None.
Permitted content: Text, possibly with escaped characters (like é).
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
有关详细信息,请参阅
推荐阅读
- python - 如何在 Azure 机器学习 Juypyter Notebooks 中安装 python ta-lib 库
- python - 如何更改我的代码以从此列表中绘制表格?
- javascript - url.content 不加载图像 javascript 和 asp.net mvc
- c# - 仅将字典中复杂类型的一些记录序列化为 JSON
- python - 在 Python 中使用 Selenium 确定为什么在列表中的特定位置捕获循环
- github - 如何在 GitHub 上嵌入视频?
- python - 从类中返回一个名为 temperature 的函数并将其打印到另一个文件中
- android - getSnapshots() 不适用于 Firestore 分页适配器
- java - 如何计算当月剩余天数?
- android - 颤振列表视图