2016-06-08 44 views
0

controller.js

$scope.getElectInfo=function(){ 
     var selectedVal = $("#countriesList option:selected").val(); 
     if (selectedVal != 0) { 
     $.get(APP_URL+ "/political/ElectionType/GetElectionTypesByCountry?countryId=" 
           + selectedVal, 
         function(data, status) { 
         $scope.data1=data; 
         console.log($scope.data1); 
         }); 
        $scope.Structure = true;  
    }else 
    { 
    $scope.Structure = false; 
    } 
     } 

HTML

<select id="countriesList" ng-change="getElectInfo()" ng-model="getElectionInfo"> 
     </select> 
     <div ng-show="Structure" class="content"> 

<figure class="org-chart cf"> 
<ul class="administration"> 
    <li>     
    <ul class="director"> 
     <li> 
     <ul class="subdirector"> 
     </ul> 
     <ul class="departments cf">        
      <li><a ><span ng-repeat="cname in country">{{cname.countryName}}</span></a></li> 

      <li class="department dep-b" ng-repeat="types in data1"> 
      <a ><span>{{types.name}}</span></a> 
      </li> 

在上面controller.js我得到全国大选明智类型的数据,在html页面,当我第一次选择国家$ scope.data1不更新在视图中,选择第二次更新可以任何一个帮助我什么是问题!

+1

删除行以获取选定值并将其替换为您的变量getElectionInfo。 确保您的条件“!= 0”为真,并检查getElectionInfo的值 – Silvinus

+0

没有运气,同样的问题 – arjun

+0

您检查了getElectionInfo的值吗?你确定请求正在执行并返回一个数组吗?你能第一次提供请求结果吗? – Silvinus

回答

1

终于我明白了,

需要放置$ scope。$ apply();功能(数据,状态){}

+0

哼哼......我明白了。我可以向你推荐一些更新以避免调用$ scope。$ apply()? 你必须调用它,因为你使用jQuery的http查询,你不在角度摘要周期。注入$ http角度服务来完成你的http请求。 Angular会自动调用他的摘要阶段来更新视图。 – Silvinus

+0

我怎么能达到这个请帮助我! – arjun

+0

在你的控制器中注入$ http,如下所示: app.controller('controllerName',['$ http',function($ http){...}]) 并用它来做你的请求: $ http .get(APP_URL +“/ political/ElectionType/GetElectionTypesByCountry?countryId =”+ selectedVal).then(function sucess(response){$ scope.data1 = response.data;},function error(error){/ * handle error */}) – Silvinus