1

我正在尝试通过共享服务“Customer.service.ts”访问 json 数据。我能够得到所有结果,直到结束(从 CustomerComponent 到 CustomerComponentPopup)。但是,不知何故,两种方式绑定不起作用。以下是我的文件,我也发布了我的控制台输出

共享服务customers.service.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);

}

组件文件,showModal() 函数的 Onclick 我正在尝试打开引导模式弹出窗口。

组件文件 customer.component.ts //

@ViewChild(customersPersonalDetailComponentPopup)
childModal: customersPersonalDetailComponentPopup;


 showModal(customerId: number) {

    this.customerService.setCurrentCustomerSubject(customerId);    
    this.editCustId = customerId;
    this.childModal.showChildModal();
  }

Booststap Modal popup Component customersPersonalDetailComponentPopup

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

public showChildModal():void {

   this.selctedCustomer = this.customerService.getCurrentCustomerSubject() 
   console.log(this.selctedCustomer);
   this.childModal.show();

}

代码的输出console.log(this.selectedCustomer);

{id:13,姓名:“Bombasto”,地址:“Nice Address2”,电话号码:“111111”,资格:“edu3”} 地址:“Nice Address2”id:13 name:“Bombasto”电话号码:“111111”资格: "edu3" 原型:
构造函数:ƒ Object() hasOwnProperty:ƒ hasOwnProperty() isPrototypeOf:ƒ isPrototypeOf() propertyIsEnumerable:ƒ propertyIsEnumerable() toLocaleString:ƒ toLocaleString() toString:ƒ () valueOf:ƒ valueOf() defineGetter定义Getter () 定义Setter:ƒ defineSetter () lookupGetterlookupGetter() lookupSetterlookupSetter () 获取原型原型() 设置原型原型()

这是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 对象访问值我错在哪里

4

0 回答 0