我正在使用AngularUI的UI-Select在我的应用程序中创建丰富的选择,并且试图将allow-clear
属性绑定到作用域上的函数或属性:
<ui-select ng-model="$parent.model" theme="bootstrap">
<ui-select-match placeholder="..." allow-clear="$parent.allowClear">{{$select.selected.DisplayText}}</ui-select-match>
<ui-select-choices repeat="opt.ID as opt in operators">
{{opt.DisplayText}}
</ui-select-choices>
</ui-select>
但是,无论我尝试什么,都无法使其正常工作。然后,在uiSelectMatch指令定义下的UI-Select源代码上找到以下代码:
$select.allowClear = (angular.isDefined(attrs.allowClear)) ? (attrs.allowClear === '') ? true : (attrs.allowClear.toLowerCase() === 'true') : false;
这可能意味着它正在对属性值进行字符串比较。
有什么办法可以解决此问题并绑定属性(甚至在初始化期间进行一次绑定)?
如果我答对了,您可以包装您的价值{{...}}
以使其发挥作用,如下所示:
<ui-select-match placeholder="..." allow-clear="{{!!$parent.allowClear}}">{{$select.selected.DisplayText}}</ui-select-match>
看到一点演示。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句