我已经尝试了很长时间来解决我的问题。问题是在通过post方法获取数据之后我的HTML内容没有更新。我的网页被$routeProvider
更改,代码如下:
socialGroup.config(function($routeProvider) {
$routeProvider.when('/my-groups', {
templateUrl: 'my-groups.html'
}).otherwise({ templateUrl: 'dashboard.html' });
});
<script type="text/ng-template" id="my-groups.html">
<div data-ng-controller="myGroups" class="form">
<div class="row">
<div class="col-md-12 col-sm-12"><h1>My Groups</h1></div>
</div>
<br/>
<div class="col-md-12 col-sm-12">
<table class="table table-hover table-inverse">
<thead>
<tr class="success">
<th>SN</th>
<th><i class="fa fa-users" aria-hidden="true"></i>Group Name</th>
<th><i class="fa fa-wrench" aria-hidden="true"></i>Action</th>
<th><i class="fa fa-sun-o" aria-hidden="true"></i>Status</th>
</tr>
</thead>
<tbody>
<div class="row" data-ng-repeat="group in groups">
<tr class="info">
<th scope="row">{{group.id}}</th>
<td>
<a href="#/stays-group/{{group.token}}" class="text-info" title="View {{group.name}} posts.">
<b>{{group.name}}</b>
</a>
</td>
<td>
<a href="{{group.link}}" title="{{group.label}}">
<b>{{group.label}}</b>
</a>
</td>
<td title="Group is active">
<label data-ng-show="group.active" class="text-success" ><b>Active</b></label>
<label data-ng-hide="group.active" class="text-danger" ><b>Inactive</b></label>
</td>
</tr>
</div>
</tbody>
</table>
</div>
</div>
</script>
socialGroup.controller('myGroups', function($scope, $http) {
$scope.groups = [];
$http({
method: "post",
url: 'my-groups-link',
data: $.param({ token:sha1( Math.random() ) }),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function success(response) {
$scope.groups = response.data;
//$scope.$apply();
//$scope.$applyAsync();
console.log($scope.groups);
}, function error(response) {});
});
我观察了我的控制台并显示数据来自服务器,但数据未更新以供查看。
任何建议都将受到赞赏。
答案 0 :(得分:1)
不确定这是否是问题,但您<div>
<tr>
使用ng-repeat
<tr>
循环访问您的数据
<tbody>
<tr class="info" data-ng-repeat="group in groups">