0

我在我的angularjs項目中使用了typeahead當我使用typeahead屬性時,文本框無法正常工作

我必須用typeahead屬性顯示在文本框中以下值:

$scope.cities = [{id:1,address:'Berlin'}, 
        {id:2,address:'Bonn'}, 
        {id:3,address:'London'}, 
        {id:4,address:'Miami'}]; 

這裏是輸入文本框與typeahead屬性:

<input type="text" 
ng-model="city" 
ng-model="initFoo(1)" 
uib-typeahead="city as city.address for city in cities | filter:$viewValue" 
class="form-control" 
typeahead-show-hint="true" 
typeahead-min-length="0"/> 

這裏是一個plunker

當初始值設置爲initFoo時,我無法刪除所選文本框或鍵入文本框。

任何想法如何設置初始值,並保持我的文本框可選和可打印?

回答

0

你必須使用ng-init而不是ng-model初始化模式

<input type="text" 
    ng-init="city = initFoo(1)" 
    ng-model="city" 
    uib-typeahead="city as city.address for city in cities | filter:$viewValue" 
    class="form-control" 
    typeahead-show-hint="true" 
    typeahead-min-length="0"/>` 
相關問題