2015-10-29 63 views
0

我有這樣的代碼:不能使用角1.4.7在代碼

<!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> 

我一直在努力與被遷移該代碼角1.4.But我不不知道我的代碼有什麼問題或者需要改變什麼。代碼在Angular 1.1.1中完美地工作,但是當我將角源更改爲具有較高版本的js時,全部變黑。

+0

你需要真的看看這個解釋所有東西的答案http://stackoverflow.com/a/28728380/2435473 –

回答

0

一對夫婦的奇怪的事情脫穎而出:

  1. 可以使用NG-模型,沒有數據 - *前綴。

  2. $ scope.selectedCountry沒有在任何地方初始化。

  3. 需要您的應用程序與NG-應用指令連接:NG-應用程序= 「my_app應用」 ID = 「NG-應用」

  4. 你沒有一個模塊或控制器定義

我的建議是找出哪個版本的AngularJS開始破壞你的代碼,以及最近的代碼是否仍然適用。然後閱讀發佈文檔,查看可能會破壞您的代碼的更改。