我有currentDistrict
要顯示在頁面上。 初始化爲空字符串:
$scope.currentDistrict = '';
,後來被填充了的WebAPI電話:
...
$scope.currentDistrict = data.currentDistrict;
...
檢索到的區信息顯示在diretive:
<district-selector current="currentDistrict"></district-selector>
而且,是使用json對象的頁面中的表單:
$scope.address = {
'district': $scope.currentDistrict,
'name': '',
'street': '',
'city': '',
'state': '',
'zip': '',
'comments': ''
};
的形式使用該address
對象:
我希望在$scope.address.district
值會隨currentDistrict
改變。說,如果我改變當前的區域,不僅<district-selector>
會改變,但表格中的只讀文本框也應該改變。
但它從來沒有。
所以問題是:如何改變$scope.address.district
當$scope.currentDistrict
有變化?
如果'district': $scope.currentDistrict,
不會設置綁定,那麼聽取一個變量的更改並應用於另一個變量的正確方法是什麼?
謝謝。第一次聽說'$ watch'。它只是工作! – Blaise