javascript - AngularJS: Assign default value for binding value -
i doing dashboard live update, after $http call when db returns null object want assign default value zero
$scope.sap=0; $http({ method: 'get', url: 'gettilesdataforprjectreport.do', }).then(function(response){ if(response.data.proj==='sap'){ $scope.sap=response.data; } } });
<div style="height:20%; background-color:#ff9e97;"> <p id="colorpalletdashboardtilered"> {{sap.red}}</p> <p id="colorpalletdashboardtileamber">{{sap.amber}}</p> <p id="colorpalletdashboardtilegreen">{{sap.green}}</p> </div> <div style="height:18%; background-color:#ff8a81;"> <p> total projects : {{sap.totalproj}} </p> </div>
if sap not in response data, need display 0 in sap bindings, if assign 0 $scope.sap, it's not reflecting in html. know done ng-hide <p>
tag, what's simplest solution
<!-- language: lang-js --> <div style="height:20%; background-color:#ff9e97;"> <p id="colorpalletdashboardtilered"> {{sap.red || 0}}</p> <p id="colorpalletdashboardtileamber">{{sap.amber || 0}}</p> <p id="colorpalletdashboardtilegreen">{{sap.green || 0}}</p> </div> <div style="height:18%; background-color:#ff8a81;"> <p> total projects : {{sap.totalproj || 0}} </p> </div> (or) //define $scope.default = 0; <div style="height:20%; background-color:#ff9e97;"> <p id="colorpalletdashboardtilered"> {{sap.red || default}}</p> <p id="colorpalletdashboardtileamber">{{sap.amber || default}}</p> <p id="colorpalletdashboardtilegreen">{{sap.green || default}}</p> </div> <div style="height:18%; background-color:#ff8a81;"> <p> total projects : {{sap.totalproj || default }} </p> </div> <!-- end snippet --> think, can try or
i think can try this
Comments
Post a Comment