2013-09-22 128 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會讓我使用動態輸入類型。