2016-08-03 76 views
0

我有兩個輸入字段(輸入字段1 &輸入字段2),它們具有自動填充選項。如果我選​​擇輸入字段1中的一個選項,那麼所選擇的選項不應顯示在輸入字段2的選項中。去做?如何避免在下一個輸入字段中顯示選定的選項?

input field 1 
<input type="text" ng-model="type1" uib-typeahead="value for value in gettype($viewValue)" > 

input field 2 
<input type="text" ng-model="type2" uib-typeahead="value for value in gettype($viewValue)"> 

$scope.gettype = function(val) { 
return $http.get('api', { 
    params: { 
    type: val, 
    sensor: false 
    } 
}).then(function(response){ 
    return response.data.type; 
}); 
}; 

這只是一個示例代碼做即時通訊的規劃是建立一個NG重複其重複,因爲我想

+0

您可以通過使用在[自動完成](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autocomplete)屬性試試2個字段。 –

+0

@MarioAlexandroSantini thx快速響應。即時通訊使用ui.bootstrap.typeahead –

+0

@Aswincj如其他用戶已經問過,如果您向我們提供代碼示例,那麼您將更容易找到幫助。 –

回答

1

可以使用NG-模糊選項輸入字段儘可能多

考慮autofille_data作爲數據

我們可以呼籲NG模糊函數

$scope.remode(autofill_data){ 
var index=autofill_data.indexOf($scope.input_val1); 
autofill_data.splice(index, 1); 
} 

其中$ scope.input_val1是輸入字段1中的值。

0

重複用於創建文本框。 之後,您需要刪除已選擇的那些值。例如:

html code 

<span"><input type="text" ng-model="x.name1"</span> 
<span"><input type="text" ng-model="x.name2"</span> 
<span"><input type="text" ng-model="x.name3"</span> 

js code: 
Suppose your suggestion values are coming from array named $scope.usStates. 
now you have to remove compare both value inside x an $scope.usStates and remove the matching element from $scope.usStates. you can use index of particullar element and splice method for removing an element. 
example: 
$scope.usStates.splice(index, 1); 

$scope.usStates = [ 
    { name: 'ALABAMA', abbreviation: 'AL'}, 
    { name: 'ALASKA', abbreviation: 'AK'}, 
    { name: 'AMERICAN SAMOA', abbreviation: 'AS'}, 
    { name: 'ARIZONA', abbreviation: 'AZ'}, 
    { name: 'ARKANSAS', abbreviation: 'AR'}, 
    { name: 'CALIFORNIA', abbreviation: 'CA'}, 
    { name: 'COLORADO', abbreviation: 'CO'}, 
    { name: 'CONNECTICUT', abbreviation: 'CT'}, 
    { name: 'DELAWARE', abbreviation: 'DE'}, 
    { name: 'DISTRICT OF COLUMBIA', abbreviation: 'DC'}, 
    { name: 'FEDERATED STATES OF MICRONESIA', abbreviation: 'FM'}, 
    { name: 'FLORIDA', abbreviation: 'FL'}, 
    { name: 'GEORGIA', abbreviation: 'GA'}] 

Thanks. 
相關問題