angular: Language Service: Identifier 'valid' is not defined. 'NgForm' does not contain such a member

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior If you open documentation for NgForm https://angular.io/docs/ts/latest/api/forms/index/NgForm-directive.html you will see example:

@Component({
  selector: 'example-app',
  template: `
    <form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate>
      <input name="first" ngModel required #first="ngModel">
      <input name="last" ngModel>
      <button>Submit</button>
    </form>
    <p>First name value: {{ first.value }}</p>
    <p>First name valid: {{ first.valid }}</p>
    <p>Form value: {{ f.value | json }}</p>
    <p>Form valid: {{ f.valid }}</p>
  `,
})

Notice f.valid usage, however language service complains:

Error:(13, 58) Angular: Identifier 'valid' is not defined. 'NgForm' does not contain such a member

The same error appears for custom directive with getter:

Error:(5, 43) Angular: Identifier 'selectedItems' is not defined. 'TableComponent' does not contain such a member

Expected behavior

No error.

  • Angular version: 4.0.0, maybe 2.x.x also

  • Language: [TypeScript X.X]

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (2 by maintainers)

Commits related to this issue

Most upvoted comments

The problem is still not resolved! It generally appears every time you reference a property on a variable that is declared as ‘any’ with the dot notation, bracket notation works. I don’t understand why this issue is closed when the problem obviously persists!

I’m getting the same thing for ngModel. I have upgraded to 4.1.1. The first example on this page https://angular.io/docs/ts/latest/api/forms/index/NgModel-directive.html give an error "Identifier ‘valid’ is not defined. ‘NgModel’ does not contain such a member.

The problem still exist on version “@angular/language-service”: “^6.0.0-rc.5”

[Angular] Identifier ‘required’ is not defined. ‘__type’ does not contain such a member

Got same issue. @angular/language-service 5.0.2 ng: Identifier ‘required’ is not defined. ‘__type’ does not contain such a member ng: Identifier ‘requiredMask’ is not defined. ‘__type’ does not contain such a member … ‘requiredMask’ is from my custom validator, anyway it doesn’t work properly even for default ‘required’ property

Similar errors :

Identifier ‘required’ is not defined. ‘__type’ does not contain such a member Identifier ‘minlength’ is not defined. ‘__type’ does not contain such a member

Same here.

Angular: Identifier 'minlength' is not defined. '__type' does not contain such a member

My component summarized:

export class CredentialsPage implements OnInit {  
  constructor (
    private fb: FormBuilder,
  ) {}

  form: FormGroup

  ngOnInit () {
    this.form = this.fb.group({
      email: [
        '',
        [Validators.required, ValidatorsUtil.email],
      ],
    })
  }
}

My template summarized:

      <div class="forms__formGroup">
        <label class="forms__inputLabel" for="email" translate="reg-label-email"></label>

        <input
          ghost
          #email
          id="email"
          type="text"
          placeholder="{{'reg-label-email' | translate}}"
          class="form-control registerCredentials__emailInput"
          [formControl]="form.controls.email" // <-- this line gets underlined in red and has an error in vsc
          [ngClass]="validationCss(form.controls.email)"
          (blur)="checkMail()">
      </div>

gives me the error:

file: 'file:///Users/manuelabergcobo/Idea/NC/nc.com/src/app/reg/pages/credentials/credentials.page.html'
severity: 'Error'
message: 'Identifier 'email' is not defined. '__type' does not contain such a member'
at: '18,26'
source: 'Angular'

I love the angular template services, they are amazing! but this error i have not been able to get rid of, i dont understand if it is a bug or if i am doing something wrong. other than this error being shown in my .html file everything else works just fine.

i hope my code example is good @chuckjaz because i have no other way to illustrate this problem, maybe i can create a plunker or something but i dont have time for it right now.

hope this helps, thank you!

In my template,

Also i got same problem that is

1: Identifier ‘minlength’ is not defined. ‘__type’ does not contain such a member. 1: Identifier ‘maxlength’ is not defined. ‘__type’ does not contain such a member.

here my code: <div *ngIf=‘greenCarName.errors.minlength’> Car name should minimum 4 chars </div> <div *ngIf=‘greenCarName.errors.maxlength’> Car name should not exceed 8 chars </div> Note : This code doesn’t stops our code and it is working fine, but shows error leke above in my template…

Can some one please help me here… i was struked here…

Would be thanks. Ram