所以,我有一个非常简单的Angular控制器。我看到Chrome调试器和胖箭头功能中的控制台之间存在分歧,作为承诺解析器。如果我在处理程序中放置一个断点,源检查器就无法定义this.scope ...但是,记录它可以正常工作。是否有一些异步的事情发生在这里我不明白,或者是否存在在promise解析器函数中确定胖箭()=>{}
函数的范围的错误?
或许,Chrome和TS +胖箭一般都有错误,在某些情况下它是如何与.js.map
一起工作的?
另外,如果我手动打开.js
文件并在执行仍然暂停时悬停,我可以将鼠标悬停在_this.scope
上,结果是正确的。
为了断点的目的,它似乎是将它限定为窗口,但代码执行正常。
class DetailController {
scope:any;
userModel:UserModel;
static $inject = ['$scope','$window', 'productModel','sessionModel','userModel', '$routeParams', '$location'];
constructor( $scope,userModel) {
this.scope = $scope;
this.userModel = userModel;
this.scope.products = null;
//if I breakpoint here, this.scope is defined
this.userModel.getCurrentUser().then(()=> {
this.scope.foo = 'bar';
// if I log scope, it is defined and correct
console.log('scope',this.scope);
//if I breakpoint here, this.scope is undefined (hovering it says undefined)
// etc...
var products = this.userModel.getProducts();
if( products.length ){
console.log( 'prods ', this.scope );
this.scope.products = products;
this.scope.product = this.scope.products[0];
}
});
}
testLambda = () => {
console.log( 'test:', this.scope ); //works
this.scope;
// breakpoint here fails to have proper this reference.
}
}
angular.module('App').controller('detailController', DetailController );
更新:我添加了测试lambda