0

I'm trying to add paging to my pdf viewer in angular and I have the following code:

<input value="1" type="number" min="1" max="{{ totalPages }}" [(ngModel)]="page">/{{ totalPages }}

I want to set the default value of the input to be "1", but this does not work. If I take out

[(ngModel)]="page"

then it work perfectly fine. What is the cause of this?

1 Answer 1

1

The input gets bound to the value of page and thus, the default value=1gets overriden. But page is probably empty / not inialized in your component, so the value is just blank. You need to initialize your page with 1 in your component e.g. like so:

page: number = 1

Then, you can also get rid of the value=1 initialization within the template.

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

1 Comment

Thank you so much!

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.