我有這樣的HTML:訪問UI元素
<select id="common_commonbundle_standard_address_country"
ng-model="common_commonbundle_standard_address.country"
required="required"
tooltip="País"
tooltip-trigger="focus"
tooltip-placement="right"
wv-def="País"
wv-cur=""
wv-err="Error!"
wv-req="The value you selected is not a valid choice"
type="text"
class="ng-scope ng-dirty ng-valid ng-valid-required">
...
</select>
而且我使用此代碼試圖common_commonbundle_standard_address.country
要監視更改:
$scope.$watch('$scope.common_commonbundle_standard_address.country', function(iso_country) {
if (iso_country)
$http.get(Routing.generate('states') + iso_country).success(function(data) {
if (data.message) {
$scope.message = data.message;
} else {
$scope.states = data;
}
}).error(function(data, status, headers, config) {
if (status == '500') {
$scope.message = "No hay conexión con el servidor.";
}
});
});
但它不工作,有什麼我做錯了?
新增控制器
app.controller( 'NewSeller',函數($範圍,$ HTTP,$ routeParams,$ fileUploader){
$scope.section = $routeParams.section == undefined ? 'main' : $routeParams.section;
$scope.aaaa = 'sdsdsdsd';
switch ($scope.section) {
case 'registro':
{
$('.seller-menu').animate({left: -230}, 300);
$scope.section = 'primer-paso';
break;
}
case 'segundo-paso':
{
break;
}
case 'main':
default:
{
break;
}
}
// Add watch for states
$scope.$watch('common_commonbundle_standard_address.country',
function(iso_country) {
$http.get(Routing.generate('states') + iso_country).success(function(data) {
if (data.message) {
$scope.message = data.message;
} else {
$scope.states = data;
}
}).error(function(data, status, headers, config) {
if (status == '500') {
$scope.message = "No hay conexión con el servidor.";
}
});
}, true);
});
您是否使用了調試器來查看您的處理程序是否被調用或者處理程序中是否有錯誤? –
'$ scope.common_commonbundle_standard_address.country'應該是'common_commonbundle_standard_address.country' – Whisher