2013-02-16 42 views
0

我在我的模型中有一個字符串數組,我想爲每個字符串創建一個文本輸入並使用Twitter Bootstrap將它們綁定到數組鍵入他們。這是我曾嘗試:用ng-repeat爲字符串數組中的每個值創建一個輸入

<div class="control-group inline" ng-repeat="offer in userinfoadd.offers"> 
    <label class="control-label" for="offer">Offer </label> 
    <div class="controls"> 
      <input type="text" bs-typeahead="typeahead" value="{{offer}}"> 
    </div> 
</div> 

這裏是我的控制器代碼:

$scope.userinfoadd = { 
    offers: ['one','two','three','four','five'] 
    }; 

    //get the typeahead 
    $http.get('data/activities.json').success(function(data) { //TODO: Stub, replace for an API call! 
    $scope.typeahead = data; 
    }); 

現在的投入渲染,但他們沒有工作。有任何想法嗎?

+0

通過「不工作」你的意思是鍵入不工作? – 2013-02-16 12:52:56

+0

typeahead的作品,但當我改變它的價值,它不會更新模型 – 2013-02-16 13:04:16

回答

0

您需要的模式綁定到輸入類似如下,那麼它應該工作:

<input type="text" bs-typeahead="typeahead" ng-model="userinfoadd.offers[$index]" /> 

看到這裏一個簡單的例子:http://jsfiddle.net/flek/hwpuT/

UPDATE

遺憾的是它不」這似乎是一個優雅的想法造成角度重新呈現你的列表,一旦你有機會輸入數組,每當你機會1個角色時模糊你的輸入。

+0

我找不到另一種方式來做到這一點,不優雅,但至少起作用。謝謝! – 2013-02-21 12:32:15

相關問題