我试图使用主题行为“属性”将str消息从组成剂发送到另一个。在类型上不存在(数据:any)=> void&quot。
我创建了一项服务,以将组件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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
EnvoyerIdPartnerDialogAuform
是您服务中的一种方法,请订阅notificationationabyubject
而不是envoyerIdPartnerdeDialogauForm
is a method in your service, subscribe to thenotificationSubject
instead在组件B中,您正在尝试订阅一种称为
EnvoyerIdpartnerDialogAuform
的方法,当然是不起作用的,因为它不应该订阅。我建议以下内容:
在您的服务中,添加以下方法,该方法可从您创建的主题中返回可观察到的方法:
然后您可以在组件B中订阅此方法:
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:
Then you can subscribe to this method in your component B: