如何在角度9中将插值绑定到ngModel

时间:2020-07-26 18:38:28

标签: angular interpolation angular9 angular2-ngmodel

Good day Community, 我在用[ngModel]绑定插值数据/值时遇到问题,我想将插值数据发送到我的数据库,这样我就可以获取和使用它,但是它的发送和返回返回一个空字符串。我的cart.component.html

 <div class="col-5 col-md-6">
                <h5>
                  <input type="text"  class="form-control user-address goat"
                    name="item"  placeholder="" [value]= "item.title" [(ngModel)]="cart.item.title" required >
                  <a routerLink="/products/shopping-hub/{{ item._id }}">{{ item.title }}</a>
                </h5>
                
                <p class="m-0">
                  <input type="text"  class="form-control user-address goat"
                  name="owner"  placeholder="" [value]= "item.owner.name" [(ngModel)]="cart.item.owner.name" required >
                  <small class="text-muted">{{ item.owner.name }}</small>
                </p>
                <p class="m-0">
                  <input type="text"  class="form-control user-address goat"
                  name="category"  placeholder="" [value]= "cart.item.category.name" [(ngModel)]="item.catgory.name" required >
                  <small class="text-muted">{{ item.category.name }}</small>
                </p>
                <a class="text-danger" (click)="removeProduct(i, item)">Remove from Cart</a>
              </div>
              <div class="col-1 col-md-2">
                <input type="number" id="price" class="form-control user-address goat"
                name="price"  placeholder="" [value]= "price" [(ngModel)]="cart.item.price" required >
                <h6 class="font-weight-bold text-danger"> ₦{{item.price}}</h6>
              </div>

和我的cart.component.ts

 cart = {
    item.title: [],
    item.owner.name:[],
    item.category.name:[],
    item.price: [],
   


  async checkout() {
    this.btnDisabled = true;
    try {
      if (this.validate()) {
        const data = await this.rest.post(
          'http://localhost:3030/api/cart',
          this.cart
        ); console.log('this.cart');
        data['success']
          ? this.router.navigate(['/products/buynow/deliveryaddress/check-out']) 
            .then(() => this.data.success(data['message']))
            .catch(error => this.data.error(error))
          : this.data.error(data['message']);
        
      } else {
        this.btnDisabled = false;
      }
    } catch (error) {
      this.data.error(error);
    }
  }

谢谢

0 个答案:

没有答案
相关问题