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.

1
  • Yes the problem is solved. Commented Apr 29, 2019 at 13:57

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Differences between value and ngValue in Angular 5

1 Comment

It does not work, I want to display a string of variables.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.