为什么我的 checkoutData 对象没有正确初始化?

问题描述 投票:0回答:1

我有以下数据对象:

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class CheckoutData {
    email:string;
    firstName:string;
    lastName:string;
    deliveryMethod: "Standard";
    paymentMethod: "Credit Card";
}

我将对象注入到组件的构造函数中并将其记录到控制台:

constructor(
    private store: Store<{ checkoutStore; cartState }>,
    public checkoutData:CheckoutData    
  ) {
    console.log('checkoutData constructor', this.checkoutData)
  }

它记录垃圾而不是实例化的数据对象:

checkoutData constructor s {}[[Prototype]]: Object

在我的视图中选择单选按钮而不是在数据对象中存储垃圾:

<div class="form-check">
    <input class="form-check-input" type="radio" id="formCheck-3" name="paymentMethod"
        [(ngModel)]="checkoutData.paymentMethod" #paymentMethod=ngModel
        (change)="saveCheckoutData()"
        [value]="paymentMethod">
    <label class="form-check-label" for="formCheck-3" style="font-size: 
    14px;">PayPal</label>
</div>
angular typescript interface typing
1个回答
2
投票

我只能看到你课堂上的一个拼写错误。

应该是

export class HelloService {
  email: string;
  firstName: string;
  lastName: string;
  deliveryMethod = 'Standard'; //typo
  paymentMethod = 'Credit Card'; //typo
}

堆栈闪电战

© www.soinside.com 2019 - 2024. All rights reserved.