Angular2/5 form validation problem?

I want to do a form check so that it can work:

flag:

Cannot read property "invalid" of undefined
at Object.eval [as updateDirectives] (EditMemberComponent.html:9)

I judge that it is the reason why the attributes of name are not automatically generated after adding the flag condition, but I don"t want to manually new FormControl, in component. It"s too troublesome

.

could you tell me how to solve the problem

Mar.01,2021

I haven't done angular for a long time, so give me a simple answer.
you added the if condition to the following code, and then you reported an error. The reason is that name does not have an invalid attribute. The ngif condition in angular is that true generates dom elements in the browser, while false does not. Only if you have dom on the page can you use-sharpname to get his element reference. So this place-sharpname= "ngModel" does not exist. Then his invalid and dirty properties are undefined. You can write it as! flag & & name?.invalid try this

Menu