2016-04-11 16 views
0

2 mdのオートコンプリートフィールドを持つビューが値のリストにバインドされています。別のフィールド選択に基づいてGET新しい値の後にドロップダウンの内容を更新します

最初のフィールドを選択すると、次のフィールドにバインドする値のリストを取得するGET要求を送信します。

私は新しいリストを取得し、私の2番目のコントロールの値を新しいリストに更新します。

しかし、UIでは、2番目のリストの値の内容が更新されず、新しいリストの値が表示されます。

2番目のコントロールは新しい値で更新されません。

私は$ scope($ apply()を試しました。

しかし、動作しません。私の開発ツールがクラッシュします。

function CompanyInfoCtrl($state, $scope, genericInfo) { 
 
    this.states = genericInfo.states; 
 
    this.cities = genericInfo.cities; 
 
     
 
    //when user Selects a State 
 
    //Update this.cities with the new ListOfCities in the selected State 
 

 
    //Call this method where field = this.cities 
 
    function(address, field) { 
 
    if(address && address.state) 
 
     return $http.get('http://localhost:8090/common/listofcitiesbystate/' + address.state).then(function(response){ 
 
     field = response.data; 
 
     }) 
 
    } 
 
}

+0

「これ」とは何ですか?それは 'CompanyInfoCtrl'それはコントローラに住んでいますか? –

+0

これはCompanyInfoCtrl – aniltilanthe

+0

もし 'CompanyInfoCtrl'がコントローラであれば、' this'ではなく '$ scope'を使用して、物事をビューに公開すると物事はより幸せになります。 –

答えて

0

モデルは、ダーティ状態に設定されていなかったので、それが新しい値で爽やかませんでした。これは、問題を解決し

//where UiElementArrayList is a list of object and is bind to md autocomplete 
//I need to update the list with new valueList based on User Action/Selection 
//GET call to fetch new data 
    this.cities = response.data 

: - - :

//1. Empty the array 
//2. Push the elements from the Response array to the UiElementArrayList 
//i.e. 
while(this.cities.length > 0) 
    this.cities.pop() 
for(i=0; i < response.data.length; i++) 
    this.cities.push(response.data[i]) 

そして、これが汚い状態にモデルを設定し、リフレッシュがそうであるように私のコードで

は、私が以前に新しい値を設定しました。私は新しいList要素を見ることができました。 :)

同じ問題が発生した場合は、これを改善/改善する方法を提案してください。

関連する問題