2013-09-22 75 views
1

我想创建一个基于给定模型的动态输入字段。 我想input元素有一个动态的type属性,但是当我这样做,我得到以下异常:AngularJs动态输入类型

Error: type property can't be changed

我读过,IE不支持输入类型的变化,因此角不允许它跨浏览器兼容性,但我相信在我的情况下有一个解决方法,即输入元素只加载一次,并且在第一次加载后不会更改。

型号:

 details: { 
      serverName: { type: 'text' }, 
      port: { type: 'number' }, 
      nickname: { type: 'text' }, 
      password: { type: 'password' }, 
      channel: { type: 'text' }, 
      channelPassword: { type: 'text' }, 
      autoBookmarkAdd: { type: 'checkbox' } 
     } 

的HTML代码:

  <ul> 
       <li ng-repeat="(index,detail) in communication.details">{{index}}: 
        <input type="{{detail.type}}" ng-model="detail.value" /></li> 
      </ul> 
+3

使用ng-switch:http://stackoverflow.com/questions/15296949/how-can-i-use-angular-to-output-dynamic-form-fields –

回答

2

正如马克表示,采用ng-switch会让我使用动态输入类型。