0

ビューに値を表示したい($scope.predicateタグ内)。式の使用が機能していないようです。$scope.reverse<p>{{ }}

app.js:

 var app = angular.module('testApp', []);
 app.controller('TestController', function($scope,$http ){
 var vm = this;
 vm.rezdata = [];
 $http.get("some rest resource...")
      .then(function(response) {
          vm.rezdata =  response.data;
          $scope.predicate = 'username';
          $scope.reverse = true;
      });
});

HTML:

<body ng-app="testApp">
    <h1>Users table </h1>  
    <table class="table table-striped" ng-controller="TestController as test">
        <p> Sorting predicate {{predicate}}; reverse = {{reverse}} </p>
        <thead>
            <tr>
                <th>#</th>
                <th>
                    Username
                </th>
                ... 
            </tr>
        </thead>
        <tbody>     
            <tr ng-repeat="datafinal in test.rezdata" >  
                <td>{{ datafinal.id}} </td>
                <td>{{datafinal.username}} </td>
                ...
            </tr>
        </tbody>        
    </table>
</body>
4

1 に答える 1

1

タグng-controller="TestController as test"をつけます。body

また、コントローラの使用controller as中に構文を使用しているため、コントローラ コンテキスト ( this) 内の値は、そのエイリアスによって HTML でアクセスできますtest{{test.predicate}}; reverse = {{test.reverse}}動作するはずです。

ただし、技術的には、を使用しているときに同じコントローラーで$scope&の両方を使用しないでください。これにより、再び混乱が生じます。ですので、に変更することをお勧めします。thiscontroller as$scopevm

<p>Sorting predicate {{predicate}}; reverse = {{reverse}}</p>
<table class="table table-striped" ng-controller="TestController as test">
   ...  
</table>
于 2016-02-18T19:43:02.493 に答える