Observable多次调用?

时间:2017-06-21 11:54:24

标签: angular

我在init上的组件中有这个:

   this.subscription =  this.ups.getCustomer().subscribe((data: any) => {
                  console.log('aaa');
                   this.fillGridFromSearchPopup({'caId': data.id});
                    return;
                });

在同样的组件中我也设置了:

  this.ups.setCustomer(this.customerId, 'BA');

现在我的服务处于循环中。我需要在这里设置,因为用户可以继续使用我需要该ID的组件,依此类推。我怎么能只召唤一次而不是多次?有什么建议吗?

这是我的服务:

 setCustomer(id, accountClassCode) {
        console.log(id,accountClassCode);
        this.customer.next({ 'id': id, 'accountClassCode': accountClassCode });
    }

    getCustomer() {
        console.log(this.customer);
        return this.customer.asObservable();
    }

0 个答案:

没有答案
相关问题