首页  >  问答  >  正文

javascript - angularjs,第二次$http.post,ng-repeat怎么更新?

刚开始使用angularjs,现在分页和查询都是由后台完成的,
所以我想我再用一次$http更新一下$scope可能就好了
但现在ng-repeat在search()后我能接收到数据,页面不会改变
这是我目前的代码。
js

app.controller('checkpoint', function($scope, $http) {
    //getData to list
        $http({
            method: 'post',
            url: '../list',
        }).then(function successCallback(response) {
                $scope.checkpoint = response.data.datas.list;
            }, function errorCallback(response) {
                console.log('请求错误');
        });
    
    
    //search
    $scope.search = function (){
        $http({
            method: 'post',
            params :{keyword:$scope.query},
            url: '../list',
        }).then(function successCallback(response) {
            console.log(response.data.datas.list)
            $scope.checkpoint = response.data.datas.list;
        }, function errorCallback(response) {
            console.log('请求错误');
        });
    };
    
});

html

<p class="rule_serch" ng-controller="checkpoint">
...
<tr ng-repeat="x in checkpoint">
    <td>{{ x.projectCode }}</td>
    <td>{{ x.station }}</td>
    <td>{{ x.code }}</td>
    <td>{{ x.circuit }}</td>
    <td>{{ x.name }}</td>
    <td>{{ x.item }}</td>
    <td>{{ x.description }}</td>
    <td>{{ x.watchedAssetCode }}</td>
</tr>
...
</p>
習慣沉默習慣沉默2686 天前588

全部回复(3)我来回复

  • PHP中文网

    PHP中文网2017-05-16 13:21:22

    search方法在哪触发的?

    回复
    0
  • 世界只因有你

    世界只因有你2017-05-16 13:21:22

    检查的时候发现了,布局中间多了一个</p>页面上没看出来

    回复
    0
  • PHP中文网

    PHP中文网2017-05-16 13:21:22

    可能angular要再次编译下,坑多。。。

    htmlContent = $compile(htmlContent)($scope);

    回复
    0
  • 取消回复