Angularjs 向Angular.get()添加延迟pr计时器以测试延迟
我正在尝试向Angular.get()请求添加延迟,以便模拟延迟或慢速网络。我想测试计时器动画是如何显示的等等 有人知道我怎样才能做到这一点吗 下面是我的.get()示例 作用域加载将是我用来包含加载动画和消息的div。您可以在success函数中添加超时(使用Angularjs 向Angular.get()添加延迟pr计时器以测试延迟,angularjs,timer,Angularjs,Timer,我正在尝试向Angular.get()请求添加延迟,以便模拟延迟或慢速网络。我想测试计时器动画是如何显示的等等 有人知道我怎样才能做到这一点吗 下面是我的.get()示例 作用域加载将是我用来包含加载动画和消息的div。您可以在success函数中添加超时(使用$timeout或window.setTimeout),如下所示: $scope.loading = true; // get all the portfolios and the products //http.ge
$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;
});
使用
不要忘记将$timeout注入控制器使用此超时,您不是在模拟响应延迟,而是在延迟调用的执行。。。
$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;
});
$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);