Z
Z
zlodiak2018-11-05 15:23:26
Angular
zlodiak, 2018-11-05 15:23:26

Why pass this again to the custom form validator?

Please help me figure it out.
LIVE DEMO
I have a form with two fields. A custom validator hangs on one of the fields. In the list of validators, I write it like this:
this.customValidator()
However, the built-in linter says that you need to pass an argument. But the validator function doesn't accept this, so I don't understand why we need to pass it. This is not clear
. If I write the validator call like this.customValidator() , then it is executed in the context of this. Because this comes before the dot. Therefore, I see no point in writing With which, by the way, there is no syntax error. This is also incomprehensible
this.floorValidator.bind(this)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-11-05
@zlodiak

You don't have to transfer anything. And you don’t need to call the validator when passing it to the FormControl constructor (do you really still not understand the difference between a function and calling it?).
What you forgot is to return some result from the validator. For example .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question