0
假設我有以下的數據,我使用角事先鍵入的內容:轉換價值在飛行中
$scope.users= UserResource.query();
//$scope.users= [{id: "1", name: "John"}, {id:"2", name: "Tom"}]
是否有可能作出預輸入綁定到號ID,而不是字符串ID服務器獲取號碼? 例如,我希望$ scope.person.id爲而不是「1」因此,當我選擇一個值時,我不會收到任何投訴。現在,因爲ID是字符串類型的,我的號碼字段得到這個錯誤:錯誤:[ngModel:numfmt]預計1
是一些
事情是這樣的:
<input ng-model="person.id class="form-control" type="number" typeahead="parseInt(user.id) as user.name for user in users | filter:$viewValue" />
以上沒有按不起作用,下列情況也是如此:
<input ng-model="person.id class="form-control" type="number" typeahead="user.id as user.name for user in users | filter: number | filter:$viewValue" />
PS當然,我不需要對id字段進行任何客戶端驗證。這只是一個快30秒的例子來說明問題。
將取代'型= number'用'類型=文本模式=「\ d +」'是一種選擇「 – Icycool
是的,這是?一個很好的選擇,我從來沒有意識到!如果你可以發佈這個答案,會很棒。 –