Raghav
Raghav

Reputation: 1229

How to get the function result in ng-repeat in AngularJS?

In ng-repeat trying to display the location address by passing the latitude and longitude to a function as shown below:

$scope.address = function(lat,lng){
    return reverseGeocode.geocodePosition(lat,lng, function(address){
        console.log(address);
        return address;
    });
};

I am using reverseGeocode.geocodePosition to fetch the address and below is my view

<table class="rideTable">
   <tbody>
      <tr class="" ng-repeat="item in rideDetailsArray">
         <td class="ridTd">
            <div class="rideName">Ride {{$index + 1}}</div>
         </td>
         <td>
            <p>Pick location : {{address(item.pick_lat,item.pick_long)}}</p>
            <p>Drop location : {{address(item.drop_lat,item.drop_long)}}</p>
         </td>
      </tr>
   </tbody>
</table>

Pick location and drop location is not displaying in the view. How can i fix this and can i get any help.

Upvotes: 0

Views: 62

Answers (3)

jose
jose

Reputation: 1054

try this call function from ng-repeat

     $scope.LocationNameFilter = function (id)//here pass your object id
{
                if ($scope.GetLocation.length > 0) {
                    var SelectStream = [];
                    if (id) {
                        SelectStream = $filter('filter')($scope.GetLocation, 
                        { _id: id });    //some condition passing your values 
                    }
                    return SelectStream[0].AddressName;
                }
                else {

                }
            };

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222582

You need to return the response as well, Change your function as

$scope.address = function(lat,lng){
    return reverseGeocode.geocodePosition(lat,lng, function(address){
        console.log(address);
        return address;
    });
};

Upvotes: 0

31piy
31piy

Reputation: 23859

$scope.address is a function which doesn't return anything. So, by default, the return value is undefined.

Thus, AngularJS displays it as blank in the view. You may want to change the function as below:

$scope.address = function(lat,lng){
    return reverseGeocode.geocodePosition(lat,lng, function(address){
        console.log(address);
        return address;
    });
};

Upvotes: 0

Related Questions