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

时间:2017-08-10 20:34:45

标签: angular behaviorsubject two-way-binding

我试图通过共享服务“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我试图打开bootstrap模式弹出窗口。

组件文件 customer.component.ts     //

@ViewChild(customersPersonalDetailComponentPopup)
childModal: customersPersonalDetailComponentPopup;


 showModal(customerId: number) {

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

Booststap模态弹出组件 customersPersonalDetailComponentPopup

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

public showChildModal():void {

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

}

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

  

{id:13,姓名:“Bombasto”,地址:“Nice Address2”,phoneNumber:“111111”,资格:“edu3”}           地址:“Nice Address2”           id:13           名称:“Bombasto”           电话号码:“111111”           资格:“edu3”            proto
          构造函数:ƒ对象()           hasOwnProperty:ƒhasOwnProperty()           isPrototypeOf:ƒisPrototypeOf()           propertyIsEnumerable:ƒpropertiesIsEnumerable()           toLocaleString:ƒtoLocaleString()           toString:ƒ()           valueOf:ƒvalueOf()            defineGetter :ƒ defineGetter ()            defineSetter :ƒ defineSetter ()            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对象

访问值时我在哪里错了

0 个答案:

没有答案