如何从ng-repeat外部获取值? 这是我从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.
});
然后我有一张桌子:
<tr ng-repeat="wall in walls">
<td>{{wall.id}}</td>
<td><a href="#" ng-click="">{{wall.link}}</a></td>
</tr>
我会在表格外的div中显示,因此在ng-repeat之外,从td中选择{{wall.link}}。我该怎么办?
答案 0 :(得分:4)
您可以实现控制器功能来设置选定的墙对象:
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;
};
}
以及您将使用的HTML格式
<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>