Angular 2双向绑定不适用于JSON对象

Angular 2双向绑定不适用于JSON对象,angular,behaviorsubject,two-way-binding,Angular,Behaviorsubject,Two Way Binding,我试图通过共享服务“Customer.service.ts”访问json数据。我能够得到所有结果,直到最后(从CustomerComponent到CustomerComponentPopup)。但是,不知何故,双向绑定不起作用。 下面是我的文件,我也发布了我的控制台输出 共享服务客户服务.ts setCurrentCustomerSubject(customerIdSubject: number) { this.customerIdSubject.next(customerIdSubje

我试图通过共享服务“Customer.service.ts”访问json数据。我能够得到所有结果,直到最后(从CustomerComponent到CustomerComponentPopup)。但是,不知何故,双向绑定不起作用。 下面是我的文件,我也发布了我的控制台输出

共享服务客户服务.ts

setCurrentCustomerSubject(customerIdSubject: number) {
    this.customerIdSubject.next(customerIdSubject);

}
getCurrentCustomerSubject(): CustomersPersonal {

  var customerId : any;

  this.customerIdSubject.subscribe(customerId1=>customerId=customerId1);
  return CUST_PERSONAL.find(x => x.id === customerId);

}
组件文件,单击showmodel()函数我试图打开引导模式弹出窗口

组件文件customer.Component.ts //

Booststap模式弹出组件CustomerPersonalDetailComponentPopup

showChildModal函数将打开模式弹出窗口。我在“this.selectedCustomer”中获得了我的愿望记录

}

输出代码console.log(this.selctedCustomer)

{id:13,姓名:“Bombasto”,地址:“尼斯地址2”,电话号码:“111111”,资格:“edu3”} 地址:“好地址2” 身份证号码:13 名称:“Bombasto” 电话号码:“111111” 资格:“教育3” proto
构造函数:ƒObject() hasOwnProperty:ƒhasOwnProperty() isPrototypeOf:ƒisPrototypeOf() propertyIsEnumerable:ƒpropertyIsEnumerable() toLocaleString:ƒtoLocaleString() toString:ƒ() valueOf:ƒvalueOf() defineGetter:ƒdefineGetter() defineseter:ƒdefineseter() lookupGetter:ƒlookupGetter() lookupSetter:ƒlookupSetter() 获取proto:ƒproto() 设置proto:ƒproto()

这是html文件代码popup.html

 <input type="text" id="name" class="form-control" name="name" [(ngModel)]="selctedCustomer.name"
           #name="ngModel" required  minlength="4" maxlength="24" value="{{selctedCustomer.name}}">

[(ngModel)]=“selctedCustomer.name”
没有显示任何内容,但它显示的是带有此符号的值
{{selctedCustomer?.name}


我不知道从json对象访问值的错误在哪里

getCurrentCustomerSubject是否进行异步调用?如果是这样,您需要在承诺解决后显示模态。正如@Mike Feltman指出的,您应该从函数getCurrentCustomerSubject()返回主题,并在打开模态的组件中订阅它。这样,您可以在异步调用完成后(从组件)打开模式,否则在实例化模式时,您的数据将为空。感谢Mike&@MaximeFlament getCurrentCustomerSubject没有进行异步调用

我正在尝试将customerId的值从“customer.component”共享到customer.component.popup,为此我使用了customer.Service,并将customerId设置为如下可观察对象

customerIdSubject=new BehaviorSubject(0)

从GetCurrentCustomesSubject,我只是试图检索与该customerId匹配的记录
MikeFeltman我如何按照您解释的方式实施。如果可能的话,请举例说明。您是否在客户服务中公开了可观察到的主题?它叫什么?如果不是,您应该,而不是“getCustomerSubject”,您可以直接订阅showModal窗口中公开的observable。。。subscribe本质上是异步的,它之外的任何设置都与它无关getCurrentCustomerSubject是否进行异步调用?如果是这样,您需要在承诺解决后显示模态。正如@Mike Feltman指出的,您应该从函数getCurrentCustomerSubject()返回主题,并在打开模态的组件中订阅它。这样,您可以在异步调用完成后(从组件)打开模式,否则在实例化模式时,您的数据将为空。感谢Mike&@MaximeFlament getCurrentCustomerSubject没有进行异步调用

我正在尝试将customerId的值从“customer.component”共享到customer.component.popup,为此我使用了customer.Service,并将customerId设置为如下可观察对象

customerIdSubject=new BehaviorSubject(0)

从GetCurrentCustomesSubject,我只是试图检索与该customerId匹配的记录
MikeFeltman我如何按照您解释的方式实施。如果可能的话,请举例说明。您是否在客户服务中公开了可观察到的主题?它叫什么?如果不是,您应该,而不是“getCustomerSubject”,您可以直接订阅showModal窗口中公开的observable。。。subscribe本质上是异步的,它之外的任何设置对它都不重要
public showChildModal():void {

   this.selctedCustomer = this.customerService.getCurrentCustomerSubject() 
   console.log(this.selctedCustomer);
   this.childModal.show();
 <input type="text" id="name" class="form-control" name="name" [(ngModel)]="selctedCustomer.name"
           #name="ngModel" required  minlength="4" maxlength="24" value="{{selctedCustomer.name}}">