DataGrid不包括在“数据网格”中;这";Angular中订阅范围中的上下文

DataGrid不包括在“数据网格”中;这";Angular中订阅范围中的上下文,angular,observable,instance,subscribe,Angular,Observable,Instance,Subscribe,在我的Angular项目中,一个页面包含两个名为“head”和“product”的组件 在“head”中,我可以更改页面的货币。。我将货币信息保存在本地存储中。。当货币发生变化时,我按“下一步”按随机数,如下所示: constructor(.........) { this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => { this.gridProduct.instance.refresh(

在我的Angular项目中,一个页面包含两个名为“head”和“product”的组件

在“head”中,我可以更改页面的货币。。我将货币信息保存在本地存储中。。当货币发生变化时,我按“下一步”按随机数,如下所示:

constructor(.........)
{
   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
        this.gridProduct.instance.refresh();
        this.gridPrice.instance.refresh();
   });
}
constructor()
{
   var this2=this;

   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
       if (this2.linensOfferId > 0) {
           this2.gridProduct.instance.refresh();
           this2.gridPrice.instance.refresh();
       }
   });
}
this.service.refreshNumberOfAllPriceByCurrency.next(Math.random())//“refreshNumberOfAllPriceByCurrency”在服务组件中定义为ReplaySubject(1)。

该行触发订阅“产品”组件,如下所示:

constructor(.........)
{
   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
        this.gridProduct.instance.refresh();
        this.gridPrice.instance.refresh();
   });
}
constructor()
{
   var this2=this;

   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
       if (this2.linensOfferId > 0) {
           this2.gridProduct.instance.refresh();
           this2.gridPrice.instance.refresh();
       }
   });
}
在订阅范围内调试时,“此”上下文不包含gridProduct、gridPrice和linensOfferId。所以它不能得到“未定义”的实例

如何在订阅范围内获取这些网格的实例

提前谢谢…

我解决了这个问题。“this.service.refreshNumberOfAllPriceByCurrency.subscribe()”事件位于构造函数中。我修改代码如下:

constructor(.........)
{
   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
        this.gridProduct.instance.refresh();
        this.gridPrice.instance.refresh();
   });
}
constructor()
{
   var this2=this;

   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
       if (this2.linensOfferId > 0) {
           this2.gridProduct.instance.refresh();
           this2.gridPrice.instance.refresh();
       }
   });
}
在subscribe()之前,我定义了this2,它等于“this”。通过这种方式,我可以从subscribe()范围内完全访问此上下文

谢谢…

我解决了这个问题。“this.service.refreshNumberOfAllPriceByCurrency.subscribe()”事件位于构造函数中。我修改代码如下:

constructor(.........)
{
   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
        this.gridProduct.instance.refresh();
        this.gridPrice.instance.refresh();
   });
}
constructor()
{
   var this2=this;

   this.service.refreshNumberOfAllPriceByCurrency.subscribe(number => {
       if (this2.linensOfferId > 0) {
           this2.gridProduct.instance.refresh();
           this2.gridPrice.instance.refresh();
       }
   });
}
在subscribe()之前,我定义了this2,它等于“this”。通过这种方式,我可以从subscribe()范围内完全访问此上下文


谢谢…

您是否尝试在ngOnInit或NgoAfterViewInit中订阅?能否在stackblitz上复制此内容?嗨,Wctiger。。我试过了。未更改。请指定如何实例化gridProduct和gridPrice。如果你得到一个错误,它们是未定义的,那么它们就不会在你想要的时候被实例化;@ViewChild(“gridPrice”,{static:false})gridPrice:any;您是否尝试过在ngOnInit或NgoAfterViewInit中订阅?能否在stackblitz上复制此内容?嗨,Wctiger。。我试过了。未更改。请指定如何实例化gridProduct和gridPrice。如果你得到一个错误,它们是未定义的,那么它们就不会在你想要的时候被实例化;@ViewChild(“gridPrice”,{static:false})gridPrice:any;