小编mad*_*kst的帖子

如何在Angular等待守卫

如果我在路线上指定三名警卫,似乎所有警卫都会立即进行评估.

{path: '', component: OptionsComponent, canActivate: [ GuardOne, GuardTwo, GuardThree]}

我遇到的问题是我不希望GuardTwo在GuardOne完成之前运行.有没有办法实现这个目标?

javascript rxjs rxjs5 angular

7
推荐指数
1
解决办法
2237
查看次数

为什么我会像在ng-file-upload示例使用代码中那样在没有延迟的情况下在AngularJS $ timeout服务中包装函数?

在大多数样品含有使用码为NG-文件上传的小提琴(的https://github.com/danialfarid/ng-file-upload)之类的一个在(http://jsfiddle.net/danialfarid/maqbzv15/1118 /),上传响应回调函数将其代码包装在$timeout服务调用中,但这些调用没有传入任何延迟参数.

$timeout(https://docs.angularjs.org/api/ng/service/ $ timeout)的Angular.js文档表明延迟是可选的,但是为什么要调用$timeoutif if not not delay code is 跑.换句话说,而不是以下,为什么不在之后做一个:

//inject angular file upload directives and services.
var app = angular.module('fileUpload', ['ngFileUpload']);

app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.uploadPic = function(file) {
file.upload = Upload.upload({
  url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
  data: {username: $scope.username, file: file},
});

file.upload.then(function (response) {
  $timeout(function () {
    file.result = response.data;
  });
}, function (response) {
  if (response.status > 0)
    $scope.errorMsg = response.status + …
Run Code Online (Sandbox Code Playgroud)

timeout angularjs ng-file-upload

5
推荐指数
1
解决办法
3860
查看次数

标签 统计

angular ×1

angularjs ×1

javascript ×1

ng-file-upload ×1

rxjs ×1

rxjs5 ×1

timeout ×1