错误TypeError:无法读取未定义的属性'serviceId'

时间:2018-09-01 14:32:21

标签: angularjs spring-boot

我使用嵌套的json作为Angular 6的输入,下面是我的json结构的样子:

{"contractId":1,"contractName":"Temp","contractServiceList":[{"id":1,"serviceId":{"serviceId":1,"serviceName":"Emergency Room"},"providerTier":"Tier 1","coinsurance":100.0,"copay":10.0,"penaltyApplies":"Y","penaltyRule":"Non Emergency ER Use","penaltyType":"Dollar Amount","penaltyValue":300.0,"deductibleApplies":"Y"}]}

在component.ts中,我的代码是:

export class AppComponent implements OnInit {
  services: Service;
  serviceId: ServiceId[];
  contract: Contract[];
  constructor(private formBuilder: FormBuilder, private router: Router, private contractService: ContractService) {  }

  addForm: FormGroup;
  ngOnInit() {
    this.serviceId = [
    {serviceId: '1', serviceName: 'Emergency Room'},
    {serviceId: '2', serviceName: 'OP Radiology'}
  ];

component.html:

 <div class="form-group col-xs-6">
      <label for="serviceName">Category Of Services:</label>
      <select id ="serviceName" formControlName="serviceName" name="serviceName" class="form-control">
    <option *ngFor="let serv of serviceId" [value]="serv.serviceId">{{serv.serviceName}}</option>
</select>
      </div>

我以(ngSubmit)=“ onSubmit”的形式提交所有值,并按如下所示进行订阅:

 onSubmit() {
    this.contractService.saveContract(this.addForm.value)
      .subscribe( data => {
alert('Contract created successfully');
      });
}

不确定为什么不能使用serviceId值。任何帮助都是可观的!

0 个答案:

没有答案