为什么'ng-attr-'不能与属性'multiple'一起使用? [英] Why 'ng-attr-' can't be used with attribute 'multiple'?

查看:46
本文介绍了为什么'ng-attr-'不能与属性'multiple'一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据条件对< select> 进行单选或多选.到目前为止,我已经尝试过:

I'm trying to make a <select> behave with single or multiple selection depending on a condition. So far I have tried:

<select  
ng-model="data.model"
ng-attr-multiple="{{myCondition ? '' : undefined}}">

(这是我正在与 https://plnkr.co/edit/一起测试的plnkrACKBMZSJc2MVSJaDBGMY?p = preview )
但这是行不通的.即使仅保留ng-attr-multiple也行不通.我在这里想念什么?

(here's a plnkr I have been testing with https://plnkr.co/edit/ACKBMZSJc2MVSJaDBGMY?p=preview)
But it won't work. Even leaving ng-attr-multiple alone won't work. What am I missing here?

推荐答案

https://docs.angularjs.org/error/$ compile/selmulti

不支持绑定到select元素的multiple属性因为在多模式和单模式之间切换会更改ngModel从实例到实例数组的对象类型破坏了模型语义.

Binding to the multiple attribute of select element is not supported since switching between multiple and single mode changes the ngModel object type from instance to array of instances which breaks the model semantics.

如果您需要在模板中使用不同类型的选择元素基于某些变量,请使用ngIf或ngSwitch指令来选择其中一个在运行时使用.

If you need to use different types of select elements in your template based on some variable, please use ngIf or ngSwitch directives to select one of them to be used at runtime.

这篇关于为什么'ng-attr-'不能与属性'multiple'一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆