Archish Archish - 6 months ago 21
AngularJS Question

How to create expression array in angularjs

This is my js code.

$scope.booking= function(docid,addid){
console.log(addid);
$http({
method: 'POST',
url: "http://localhost:81/DoctorStayServiceAngular/model/getDoctorBookingDetail.php",
params:{"doctorid":docid,"addressid":addid,"day":weekday[d.getDay()]}
//params:{"doctorid":docid}
}).then(function mySucces(response) {
//$scope.count= response.data;
i++;
$scope.count= i;
//console.clear();
});

};


and This is HTML.

<div id="DocAppoinment" class="col-sm-3" ng-init="booking(x.profileid,x.addressid)">
<span ng-bind="count"></span>
</div>


And This is my output

My outout

js function will give me 10 list,and i want to display 1 to 10 on right hand side, as you can see in output it's getting overwritten for obvious reason.

so what should do to print 1 to 10 on right hand side? is there expression array or something in angular? any suggestion?

PS: I am new to this framework.

Answer

I wouldn't call it a solid solution but one way would be to take advantage of track-by in your ng-repeat .

example: ng-repeat="x in exxes track by $index" and use {{$index+1}} to display the number in your html.

So it would look like

<div ng-repeat="x in exs track by $index">
   <div id="DocAppoinment" class="col-sm-3" ng-init="booking(x.profileid,x.addressid)">
        <span  ng-bind="count">{{$index + 1}}</span>
   </div>
</div>
Comments