Atlas91
Atlas91

Reputation: 5904

Get value from outside ng-repeat in angular

How can i get a value from outside an ng-repeat? This is my function to get values from json

function($scope, $http) {
        $http.get('https://www.mywebsite.com/images/getimages.php').
          success(function(data, status, headers, config) {
            $scope.walls = data.walls;
            console.log($scope.walls);
         }).error(function(data, status, headers, config) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
         });

then i have a table:

<tr ng-repeat="wall in walls">
                <td>{{wall.id}}</td>
                <td><a href="#" ng-click="">{{wall.link}}</a></td>            
            </tr>

i would show in a div outside the table and so outside the ng-repeat, the {{wall.link}} selected from the td. How can i do it?

Upvotes: 2

Views: 1130

Answers (1)

dfsq
dfsq

Reputation: 193251

You can implement controller function to set selected wall object:

function ($scope, $http) {

    $http.get('https://www.mywebsite.com/images/getimages.php')
        .success(function (data, status, headers, config) { /*...*/ })
        .error(function (data, status, headers, config) { /*...*/ });

    $scope.select = function (wall) {
        $scope.selectedWall = wall;
    };
}

and the in HTML you would use

<table>
    <tr ng-repeat="wall in walls">
        <td>{{wall.id}}</td>
        <td>
            <a href="#" ng-click="select(wall)">{{wall.link}}</a>
        </td>
    </tr>
</table>

<div>{{selectedWall.link}}</div>

Upvotes: 4

Related Questions