1 回答
TA贡献1797条经验 获得超4个赞
您可以将响应分配给userData并将折叠的元素绑定到它。
例如
<div id="testThis" class='collapse' ng-bind="userData.more"></div>
和
}).then(function(response) {
const userData = $scope.userData.find(data => data.user_id === user_id);
userData.more = response;
});
这是一个实例(我做了一些必要的更改以使其工作,但想法是相同的)。
angular.module('app', []).controller('ctrl', function($scope, $http) {
$scope.userData = [{
user_id: 8
}];
$scope.getInfo = function(user_id) {
toSend = {
"user_id": user_id
}
$http({
method: 'GET',
url: 'https://jsonplaceholder.typicode.com/todos/1',
//data: toSend,
}).then(function(response) {
const userData = $scope.userData.find(data => data.user_id === user_id);
userData.more = response;
})
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<span ng-repeat="topdata in userData">
<span style="white-space: pre">
<a
class="collapsed"
data-target="#testThis"
data-toggle="collapse"
ng-click="getInfo(topdata.user_id)"
>
<pre><i class='fa fa-plus'></i><span>Some text</span></pre>
</a>
</span>
<div id="testThis" class="collapse" ng-bind="topdata.more | json">
<!-- API content goes here -->
</div>
</span>
</div>
添加回答
举报