Javascript Can';t在代码中使用角度1.4.7
我有以下代码:Javascript Can';t在代码中使用角度1.4.7,javascript,angularjs,migration,Javascript,Angularjs,Migration,我有以下代码: <!DOCTYPE html> <html> <head> <title>Lists Test</title> <script src="https://code.angularjs.org/1.1.1/angular.min.js"></script> <script> function Controller($scope) { $scope.backupC
<!DOCTYPE html>
<html>
<head>
<title>Lists Test</title>
<script src="https://code.angularjs.org/1.1.1/angular.min.js"></script>
<script>
function Controller($scope) {
$scope.backupCountries = {
"id": "field10",
"items": [{
"id": "10",
"StateGroupID": "0",
"name": "United State"
}, {
"id": "2",
"StateGroupID": "1",
"name": "Canada"
}]
};
$scope.backupStates = {
"id": "field20",
"StateGroups": [{
"items": [{
"id": "1",
"name": "Alabama"
}, {
"id": "2",
"name": "Alaska"
}, {
"id": "3",
"name": "Arizona"
}, {
"id": "4",
"name": "California"
}]
},
{
"items": [{
"id": "201",
"name": "Alberta"
}, {
"id": "202",
"name": "British Columbia"
}, {
"id": "303",
"name": "Manitoba"
}, {
"id": "304",
"name": "Ontario"
}]
}]
};
$scope.Countries = $scope.backupCountries;
$scope.getStates = function () {
console.log($scope.selectedCountry);
return $scope.backupStates.StateGroups[$scope.selectedCountry].items;
};
//$scope.currentStates = $scope.backupStates.StateGroups[0];
/*$scope.$watch('currentStates', function(value, oldValue){
//alert(value);
//alert(JSON.stringify(value));
//$scope.currentStates = (value == "10") ? States.StateGroups[0] : States.StateGroups[1];
});*/
};
</script>
</head>
<body>
<div ng-app ng-controller="Controller">
<h2 class="page-title">Model</h2>
<div class="row-fluid">
<div class="span4">
<label for="cboGroup">Countries</label>
<select data-ng-model="selectedCountry">
<option value="">Please Select a Country</option>
<option ng-repeat='country in Countries.items' value='{{country.StateGroupID}}'>{{country.name}}</option>
</select>
</div>
<div class="span4">
<label for="cboItem">States</label>
<select data-ng-model="selectedState">
<option value="">Please select a state</option>
<option ng-repeat='state in getStates()'>{{state.name}}</option>
</select>
</div>
<div class="well">what I am trying to archive is that the items are changing each time the group changes.</div>
<div>Countries : {{Countries.items | json}}</div>
<div>States : {{getStates()}}</div>
</div>
列表测试
功能控制器($scope){
$scope.backupCountries={
“id”:“字段10”,
“项目”:[{
“id”:“10”,
“StateGroupID”:“0”,
“名称”:“美国”
}, {
“id”:“2”,
“StateGroupID”:“1”,
“姓名”:“加拿大”
}]
};
$scope.backupStates={
“id”:“field20”,
“国家集团”:[{
“项目”:[{
“id”:“1”,
“姓名”:“阿拉巴马州”
}, {
“id”:“2”,
“名称”:“阿拉斯加”
}, {
“id”:“3”,
“名称”:“亚利桑那州”
}, {
“id”:“4”,
“名称”:“加利福尼亚”
}]
},
{
“项目”:[{
“id”:“201”,
“姓名”:“阿尔伯塔省”
}, {
“id”:“202”,
“名称”:“不列颠哥伦比亚省”
}, {
“id”:“303”,
“名称”:“马尼托巴”
}, {
“id”:“304”,
“名称”:“安大略省”
}]
}]
};
$scope.Countries=$scope.backupCountries;
$scope.getStates=函数(){
console.log($scope.selectedCountry);
返回$scope.backupStates.StateGroups[$scope.selectedCountry].items;
};
//$scope.currentStates=$scope.backupStates.StateGroups[0];
/*$scope.$watch('currentStates',函数(value,oldValue){
//警报(值);
//警报(JSON.stringify(value));
//$scope.currentState=(值=“10”)?States.StateGroups[0]:States.StateGroups[1];
});*/
};
模型
国家
请选择一个国家/地区
{{country.name}
州
请选择一个状态
{{state.name}
我试图存档的是,每次组更改时,项目都会更改。
国家:{{Countries.items}
状态:{{getStates()}}
我一直在努力将这段代码迁移到Angular 1.4.0版本,但我不知道我的代码出了什么问题,也不知道应该修改什么。代码在Angular 1.1.1中运行得非常完美,但当我将Angular源代码更改为js的更高版本时,所有代码都变为黑色。有几件奇怪的事情非常突出:
我的建议是找出AngularJS的哪个版本开始破坏您的代码,以及您的代码仍然可以使用的最新版本。然后阅读发布文档,看看所做的哪些更改可能会破坏您的代码。您需要真正了解这个答案,它解释了所有问题