Умножьте данное число на номер ввода

for pair in zip(A, B):
    print ">"+'\n'.join(pair)
0
задан miqh 16 January 2019 в 23:52
поделиться

2 ответа

  1. Убедитесь, что вы добавили FormsModule в свой массив импорта в файле app.module.ts

app.module.ts:

import { FormsModule } from '@angular/forms';

@NgModule({
  declarations: [...],
  imports: [
    ...
    FormsModule
  ],
  ...etc
})
  1. HTML-файл [116 ]
<div>
   <p>{{ activeProduct.price }} </p>
   <label for="amount">Amount</label>
   <input type="number" (change)="calculateTotal() [(ngModel)]="activeProduct.numOfItems"/>
   <br>
   <hr>
   <p style="float: left;">Total price:</p>
   <p [(ngModel)]="totalCost">{{ totalCost }}</p>
</div>
  1. TS File
export class AppComponent {
    activeProduct: any = {
        price: 12,
        name: 'pizza',
        numOfItems: 0
    };

    totalCost: number = 0;

    constructor() {}

    calculateTotal(): number {
        return this.totalCost = this.activeProduct.numOfItems * this.activeProduct.price;
    }
}

не самый элегантный способ, но он доставит вас туда. Я думаю, что самая большая проблема - FormsModule

0
ответ дан Mehrad 16 January 2019 в 23:52
поделиться

Вы не привязали поле ввода к чему-либо, используйте ngModel

<input type="number" [(ngModel)]="inputNum" style="width:40px; float:right;" />

или если вы не хотите использовать модуль форм

<input type="number" (change)="inputNum = $event.target.value" style="width:40px; float:right;" />
0
ответ дан Adrian Brand 16 January 2019 в 23:52
поделиться
Другие вопросы по тегам:

Похожие вопросы: