我试图使用主题行为“属性”将str消息从组成剂发送到另一个。在类型上不存在(数据:any)=> void&quot。

发布于 2025-02-03 07:12:07 字数 1296 浏览 3 评论 0原文

我创建了一项服务,以将组件A的字符串发送到组件B:

this is the service (FactureService) :


  public notificationSubject= new Subject<string>()


  constructor() {}

envoyerIdPartnerdeDialogauForm(data){
   this.notificationSubject.next(data);
  }

这是组件a:

constructor(  private factureservice : FactureService) { }

 ngOnInit(): void {}
 
sendidPartenaire(data){
  this.factureservice.envoyerIdPartnerdeDialogauForm(data.value)
  Entre id: <input type ='text' #message />
<button   (click)="sendidPartenaire(message)">Send message</button>

这是组件B:

  idpartnerstring : string ;
constructor(){   private factureservice: FactureService}



//the problem is here in the subscribe :
//Property 'subscribe' does not exist on type '(data: any) => void'
  ngOnInit(): void {
this.factureservice.envoyerIdPartnerdeDialogauForm.subscribe(d => {

  this.idpartnerstring=d;
});

}

#我尝试了服务中的Addind返回,但仍然有同样的问题

I created a service to send a string from component A to componant B :

this is the service (FactureService) :


  public notificationSubject= new Subject<string>()


  constructor() {}

envoyerIdPartnerdeDialogauForm(data){
   this.notificationSubject.next(data);
  }

and this is the component A :

constructor(  private factureservice : FactureService) { }

 ngOnInit(): void {}
 
sendidPartenaire(data){
  this.factureservice.envoyerIdPartnerdeDialogauForm(data.value)
  Entre id: <input type ='text' #message />
<button   (click)="sendidPartenaire(message)">Send message</button>

and this is component B :

  idpartnerstring : string ;
constructor(){   private factureservice: FactureService}



//the problem is here in the subscribe :
//Property 'subscribe' does not exist on type '(data: any) => void'
  ngOnInit(): void {
this.factureservice.envoyerIdPartnerdeDialogauForm.subscribe(d => {

  this.idpartnerstring=d;
});

}

#i tried addind return in the service but still got the same problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像你 2025-02-10 07:12:07

EnvoyerIdPartnerDialogAuform是您服务中的一种方法,请订阅notificationationabyubject而不是

  ngOnInit(): void {
    this.factureservice.notificationSubject.subscribe(d => {

      this.idpartnerstring=d;
    });
  }

envoyerIdPartnerdeDialogauForm is a method in your service, subscribe to the notificationSubject instead

  ngOnInit(): void {
    this.factureservice.notificationSubject.subscribe(d => {

      this.idpartnerstring=d;
    });
  }
绳情 2025-02-10 07:12:07

在组件B中,您正在尝试订阅一种称为EnvoyerIdpartnerDialogAuform的方法,当然是不起作用的,因为它不应该订阅。

我建议以下内容:

在您的服务中,添加以下方法,该方法可从您创建的主题中返回可观察到的方法:

notificationSubject$(): Observable<string> {
   return this.notificationSubject.asObservable();
}

然后您可以在组件B中订阅此方法:

ngOnInit(): void {
   this.factureservice.notificationSubject$().subscribe(value => {
      this.idpartnerstring = value;
   });
}

In your component B, you are trying to subscribe to a method called envoyerIdPartnerdeDialogauForm which of course will not work because it is not supposed to be subscribed to it.

I suggest the following:

In your service, add the following method, which returns you an observable from the subject that you created:

notificationSubject$(): Observable<string> {
   return this.notificationSubject.asObservable();
}

Then you can subscribe to this method in your component B:

ngOnInit(): void {
   this.factureservice.notificationSubject$().subscribe(value => {
      this.idpartnerstring = value;
   });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文