【发布时间】:2014-02-24 09:11:58
【问题描述】:
我正在使用 ui-select2,但在使用 allowClear: true 时遇到问题。 allowClear 正在按预期工作,但需要在清除输入时触发事件。 我尝试通过 $watch 实现它,但没有成功。有没有办法在 angularjs 中使用 select2-removed 函数。
<select ui-select2="timeConfig" ng-model="time" data-placeholder="{{TIME.placeholder}}">
<option value=""></option>
<option ng-repeat="option in TIME.options" value="{{option.value}}">
{{option.title}}</option>
</select>
//在控制器中
$scope.timeConfig = {
allowClear : true
}
$scope.$watch('time', function(newVal,oldVal) {
if(newVal=='') {
console.log("Value is changed to clear");
}
console.log("Changing and making new request");
}, true);
当我点击清除按钮时 $watch 没有被触发(模型中的值保持不变)
【问题讨论】:
-
清除按钮有什么作用?
-
它将select2中的选定选项清除为占位符。
-
请同时包含按钮标记和js。
-
select2在选择每个项目时,在其自己的小x(横跨)上添加清除按钮。 span>
-
我明白了。你能创建一个现场演示来演示这个问题吗? (例如使用plunker)
标签: javascript jquery angularjs ui-select2