javascript - 如何在 Angular js中显示加载图像

标签 javascript angularjs

您好,伟大的 Stackoverflow,我正在学习 Angular JS,所以我正在通过 Angular JS 查询数据库记录,一切正常。现在我想在加载数据库内容时显示加载图像,并且一旦加载内容,图像就会消失。请问我该如何实现这一点。谢谢

下面是工作代码

var app = angular.module('angularTable', ['angularUtils.directives.dirPagination']);

app.controller('listdata',function($scope, $http){
    $scope.users = []; //declare an empty array

    $http.get("data.php").success(function(response){ 

        $scope.users = response;  //ajax request to fetch data into $scope.data
    });

    $scope.sort = function(keyname){
        $scope.sortKey = keyname;   //set the sortKey to the param passed
        $scope.reverse = !$scope.reverse; //if true make it false and vice versa
    }
});

最佳答案

您可以添加类似 $scope.loading = true; 的内容之前$http.get("data.php").success(function(response){线。 和$scope.loading = false;内部成功函数。 在标记中,类似 <table ng-hide="loading"><img ng-show="loading" src="loader.gif">

关于javascript - 如何在 Angular js中显示加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38037570/

相关文章:

javascript - 指令和 Controller 中的两种方式绑定(bind)

javascript - AngularJS 相当于 jQuery 切换显示/隐藏部分

javascript - Mapbox 使用哪种投影

javascript - html2canvas 无法加载未定义的图像

javascript - 文件上传完成删除文件名?

javascript - 如何在 AngularJS 中观察作用域的所有变化?

javascript - 如何将值从子页面发送到父页面

javascript - 事件 + jshint 上的 d3.js 可能存在严格违规

javascript - 为什么在 Javascript 中 this 上下文会根据调用方式而变化?

javascript - 如何在 Angular 中为多选选择标签设置多个默认值