ボタンを使用して読み込まれたデータを更新するメソッドを追加する際に問題があります。 マイコントローラー:AngularJS Reloadボタン?
.controller('mainCtrl', function($scope, $http, User) {
$scope.loading = true;
User.get()
.success(function(data) {
$scope.users = data;
$scope.loading = false;
});
});
サービス:
angular.module('userService', [])
.factory('User', function($http) {
return {
get : function() {
return $http.get('/api/users/get');
}
}
});
そして、これが私の見解はどのように見えるかです:あなたがそこに見ることができるよう
が<div class="box" ng-app="userApp" ng-controller="mainCtrl">
<div class="box-header">
Angular Test <button class="btn btn-success" ng-click="get()"><i class="fa fa-refresh"></i> Reload</button>
</div>
<div class="box-body">
<p class="text-center" ng-show="loading"><span class="fa fa-meh-o fa-5x fa-spin"></span></p>
<table ng-hide="loading" class="table table-responsive">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Realname</th>
<th>Email</th>
<th>Phone</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>@{{ user.id }}</td>
<td>@{{ user.name }}</td>
<td>@{{ user.realname }}</td>
<td>@{{ user.email }}</td>
<td>@{{ user.phone }}</td>
<td>
<a href="/admin/profile/@{{ user.id }}" class="btn btn-block btn-primary btn-sm">
<i class="fa fa-user" aria-hidden="true"></i> Profile
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
、私はリロードボタンを持ってしようとしていますng-click="get"
を使用しています。しかし、これは何もしません。そこに電話する必要がありますか?
ng-hide/ng-showの代わりにng-ifを試して、$ scope.loading = trueをfalse、$ scope.loading = falseをtrueに置き換えることはできますか? コントローラ内のすべてのデータを取得しましたか?あなたはconsole.logでチェックしましたか? – Wandrille
データの読み込み中です。ボタンがリロードを開始していないことだけです。 – Scarwolf
申し訳ありませんが、私は見ていません。あなたの関数はどこで定義されていますか?それはあなたのコントローラーで定義されています。 – Wandrille