0

I have a problem, I would like to do this:

<mat-form-field>
  <mat-label>Period:</mat-label>
  <input matInput [value]="period.month / period.year" disabled>
</mat-form-field>

But that does not work.

enter image description here


On the other hand, this works:

<mat-form-field>
  <mat-label>Period:</mat-label>
  <input matInput [value]="period.year" disabled>
</mat-form-field>

Would anyone have a solution to display multiple variables in the value of an input?

EDIT: [ngValue] does not work, I want to display a string of variables.

Quentin
  • 1,865
  • 2
  • 24
  • 40

3 Answers3

1

I think[value] only supports strings. Try [ngValue] instead.

Differences between value and ngValue in Angular 5

Friso Hoekstra
  • 845
  • 2
  • 9
  • 24
1

Since [value] needs a string, you could set its value to

[value]="period.month + '/' + period.year"

which resolves to a string. In your code, period.month is divided by period.year and resolves to NaN if at least one of them cannot be changed to a number.

Fundhund
  • 141
  • 5
0

[value] always accepts String as an input, but [ngValue] accepts Object. Try using [ngValue]

Bishal Jaiswal
  • 1,684
  • 13
  • 15