2017-06-06 50 views
1

我正在为每个对象设备做进度条。如何查看所有ng-init内容?

这里是我的AngularJS代码:

$scope.progressBarEquipements=function(idEquipement) { 

    $http.get(url+"/RestResponseCheckLists?idEq="+idEquipement) 
    .success(function(data) { 
      $scope.Pourcentage = data; 
     }).error(function(err, data) { 
      console.log("error : " +data); 
    }); 
}; 

该函数返回$scope.progressBarEquipements=function(idEquipement)

console.log("data "+Pourcentage); 
/** 
* [{'NB_Resp':2,'NB_checks':154}] //For the first object And the others not 
*/ 

这里是我的HTML代码:

<div class="col-md-4" ng-repeat="eq in Checksf" ng-init="progressBarEquipements(eq.idEquipements)"> 
      <h4 class="list-group-item-heading" >{{eq.nomEq}} </h4> 
     <div class="progress progress-lg m-b-5" > 
       <div class="progress-bar progress-bar-purple" role="progressbar" ng-repeat="p in Pourcentage" ng-style="{width:{{((p.NB_Resp/p.NB_checks) * 100)}} + '%'}"> 
        {{((p.NB_Resp/p.NB_checks) * 100) | number:0}}% 
      </div> 
    </div>     
</div> 

所以我有四个项目的设备是显示在html页面中。

$scope.Percentage仅显示 第一个对象的进度栏计算。

如何显示每个对象在进度条中的计算?

预先感谢您

回答

0

虽然,我不喜欢你正在使用NG-INIT的方式,下面应该工作:

$scope.progressBarEquipements=function(eq) { 

    $http.get(url+"/RestResponseCheckLists?idEq="+ eq.idEquipement) 
    .success(function(data) { 
     eq.Pourcentage = data; 
     }).error(function(err, data) { 
      console.log("error : " +data); 
    }); 
}; 

<div class="col-md-4" ng-repeat="eq in Checksf" ng-init="progressBarEquipements(eq)"> 
      <h4 class="list-group-item-heading" >{{eq.nomEq}} </h4> 
     <div class="progress progress-lg m-b-5" > 
       <div class="progress-bar progress-bar-purple" role="progressbar" ng-repeat="p in eq.Pourcentage" ng-style="{width:{{((p.NB_Resp/p.NB_checks) * 100)}} + '%'}"> 
        {{((p.NB_Resp/p.NB_checks) * 100) | number:0}}% 
      </div> 
    </div>     
</div> 

当时的想法是把你的函数“progressBarEquipements”完整的设备对象。这样,您可以在服务器响应时更新它。

我不喜欢使用ng-init的方法,因为 - 您的视图行为有点隐藏在您的控制器和您的模板之间。 - 如果我必须这样做,我的API会给viewmodel包含我需要显示的每个信息。

+0

根据最后修改,它与我合作,谢谢先生, – Michael1

+0

我已经看到您的编辑,并确定,我错过了“百分比”到您的对象,但我不认为应该重复ng在那里,每次只有一件物品。 –

+0

'eq.Pourcentage'返回两个对象。如何浏览。所以,添加'ng-repeat'。我测试过这种情况,它适用于我 – Michael1