我正在尝试向Angular .get()请求添加延迟,以便我可以模拟延迟或慢速网络。我想测试计时器动画的显示方式等。
有谁知道我怎么做到这一点?
以下是我的.get()
示例 $scope.loading = true;
// get all the portfolios and the products
//http.get('scripts/json/sample-products.json')
$http.get('http://www.website.com/Pricing/GetProductCatalogue')
.then(function (allProducts) {
$scope.listOfProducts = allProducts.data.Connectivity;
})
.finally(function() {
$scope.loading = false;
});
范围加载将是我用来包含我的加载动画和消息的div。
答案 0 :(得分:2)
您可以在成功功能中添加超时($timeout
或window.setTimeout
),如下所示:
$scope.loading = true;
// get all the portfolios and the products
//http.get('scripts/json/sample-products.json')
$http.get('http://www.website.com/Pricing/GetProductCatalogue')
.then(function (allProducts) {
$timeout(function(){
$scope.listOfProducts = allProducts.data.Connectivity;
},10000)
})
.finally(function() {
$scope.loading = false;
});
答案 1 :(得分:0)
使用$timeout
$scope.loading = true;
var getFunc = function(){
$http.get('http://www.website.com/Pricing/GetProductCatalogue')
.then(function (allProducts) {
$scope.listOfProducts = allProducts.data.Connectivity;
})
.finally(function() {
$scope.loading = false;
});
}
$timeout(getFunc, 1000);
不要忘记在控制器中注入$ timeout