小编tos*_*skv的帖子

Angular 2调用setInterval()undefined服务表单依赖注入

我想通过使用setInterval()每隔10分钟调用一个函数,并且在这个函数中我想使用从Angular 2的Dependency Injector获得的Service(称为auth),问题是控制台告诉我以下内容:

EXCEPTION:TypeError:this.auth未定义

  constructor(private auth: AuthService){
    setInterval(function(){ this.auth.refreshToken(); }, 1000 * 60 * 10);
  }
Run Code Online (Sandbox Code Playgroud)

setinterval typescript angular

21
推荐指数
2
解决办法
4万
查看次数

在VS Code中隐藏.js和.map文件

我可以在Visual Studio Code中使用哪种设置来隐藏某些.js和.map文件?

在此输入图像描述

typescript visual-studio-code

4
推荐指数
2
解决办法
4263
查看次数

在胖箭头方法中添加返回类型信息

我搜索了所有可能的方法,但我无法弄清楚如何组合返回类型注释和胖箭头语法.

class BasicCalculator{
    value:number;
    constructor(value:number=0){
        this.value=value;
    }
    add= (operand:number)=>{ // CAVEAT how to add return type???
        this.value+=operand;
        return this;
    }
    subtract= (operand:number)=>{
        this.value-=operand;
        return this;
    }
    multiply= (operand:number)=>{
        this.value*=operand;
        return this;
    }
    divide= (operand:number)=>{
        this.value/=operand;
        return this;
    }
}
Run Code Online (Sandbox Code Playgroud)

我试过了:

add= (operand:number)=>number { ....
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

typescript

2
推荐指数
1
解决办法
1101
查看次数

ng-repeat与过滤器和ng-if在同一元素上的角度优先级

如果在同一元素上有过滤器的ng-ifng-repeat,则即使ng-if隐藏了元素,也会调用过滤器一次.

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $timeout) {
  $timeout(function() {
    $scope.list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  }, 2000);
});

app.filter('crashyFilter', function() {
  return function(list) {
    return list.map(function(item) {
      return item + 1;
    });
  };
});
Run Code Online (Sandbox Code Playgroud)
<body ng-controller="MainCtrl">
  <div ng-if="list" ng-repeat="item in list | crashyFilter">
    {{item}}
  </div>
</body>
Run Code Online (Sandbox Code Playgroud)

在浏览器控制台中,您可以看到地图调用失败一次,因为list参数未定义.我在这里做了一个龙头.

谁知道为什么会这样?

javascript angularjs

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