2017-05-30 46 views
0

我需要即時更新typeahead建議。前端未反映它綁定到的數組上的更改。我如何解決這個問題?我使用的UI引導更新UI引導程序無法向Typeahead添加新建議

這裏有一個jsfiddle複製,增加價值,嘗試在tyeahead鍵入它,沒有更新

angular.module('ui.bootstrap.demo', ['ui.bootstrap']) 
    .controller('ModalDemoCtrl', function($rootScope, $scope, $log, $uibModal) { 

    $scope.addName = function() { 
     console.log("adding name" , $scope.name); 
     $scope.fieldNames.push($scope.name); 
    } 

    $scope.fieldNames = [{name:"Paul"},{name:"Pamela"}, {name:"Adam"}, {name:"Atrium"}]; 
}); 

回答

0

幾件事情

  1. 你是推一個字符串進入數組,您應該推入一個名稱屬性的對象,而不是

  2. 您對ng-repeat有一個限制過濾器,限制您的可見suggesti插件,你可能想刪除它,或者至少icrease它

,而不是

$scope.addName = function() { 
    console.log("adding name" , $scope.name); 
    $scope.fieldNames.push($scope.name); 
} 

$scope.addName = function(newName) { // <-- passing the $scope.name from the template 
    console.log("adding name" , newName); 
    $scope.fieldNames.push({ name: newName}); 
} 

和編輯

uib-typeahead="field as field.name for field in fieldNames | limitTo:4 | filter:{name:$viewValue}" 

uib-typeahead="field as field.name for field in fieldNames | filter:{name:$viewValue}" 

Here is an updated fiddle

+0

謝謝你,是我不好......插入串,MOD後工作正常 – Jimmy