Error 1068: The property does not exist on the angular type 2 (AOT)

advertisements

I am new in angular 2, i am making a "User Register" form but it shows error in "Property does not exist on type" in Phone number Validation.

I am compiling in JIT and AOT.

In JIT compiler shows error message and run my user register form it is working properly. but when i compile with AOT shows compilation error.

I am reading the angular 2 form validation official doc here is the link Angular 2 form validation

Below is my Html Form and compiler Output

Html Form

<form class="ui large form" method="post" (ngSubmit)="onSubmit(registerForm.form.valid)" #registerForm="ngForm" novalidate>
        <sm-loader [complete]="!formSubmited" class="inverted" text="Loading..."></sm-loader>
        <div class="form-group">
            <div class="col-md-12 img-bottom">
                <div class="col-md-offset-4">
                    <img (click)="profileImage.click()" class="img img-responsive img-circle ui middle aligned tiny circular image profileImage"
                        [src]="profileImageSrc" />
                    <input class="form-control user-reg-img" (change)="fileChangeEvent($event)" type="file" accept="image/*" #profileImage [hidden]="true"
                    />
                </div>
                <div class="col-md-12 image-padding">
                    <span class="user-reg-img-name" (click)="profileImage.click()">{{profileImageName}}</span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label><strong>Signup with Email Address:</strong></label>
        </div>

        <div class="form-group">
            <p class="success text-center">{{successMessage}}</p>
            <p class="error text-center">{{errorMessage}}</p>
            <div class="field">
                <input type="text" name="name" placeholder="Name" [(ngModel)]="register.name" #name="ngModel" required class="form-control input-reg"
                />
                <div [hidden]="name.valid || name.pristine" class="error text-left">
                    Name is required
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="field">
                <input class="form-control input-reg" type="email" name="email" placeholder="Email" [(ngModel)]="register.email" #email="ngModel"
                    required />
                <div [hidden]="email.valid || email.pristine" class="error text-left">
                    Email is required
                </div>
            </div>
        </div>

        <div class="form-group">
            <input type="text" id="mobile" class="form-control  input-reg" required minlength="10" maxlength="10" name="mobile" [(ngModel)]="register.mobile"
                placeholder="Phone Number" #mobile="ngModel" pattern="[0-9]+">
            <div *ngIf="mobile.errors && (mobile.dirty || mobile.touched)">
                <div class="error text-left" [hidden]="!mobile.errors.required">
                    Mobile Number is required
                </div>
                <div class="error text-left" [hidden]="!mobile.errors.minlength">
                    Mobile Number must be at least 10 characters long.
                </div>
                <div class="error text-left" [hidden]="!mobile.errors.maxlength">
                    Monile Number cannot be more than 10 characters long.
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="field">
                <input class="form-control input-reg" type="password" name="password" placeholder="Password" [(ngModel)]="register.password"
                    #password="ngModel" required />
                <div [hidden]="password.valid || password.pristine" class="error text-left">
                    Password is required
                </div>
            </div>
        </div>

        <div class="form-group">
            <input type="checkbox" name="isAgree" [(ngModel)]="register.isAgree" #isAgree="ngModel" required />
            <label id="label-terms-cond">I Agree to Post Bucks <a href="#">Terms & Conditions</a></label>
            <div [hidden]="!showTermsAgreeErrorMsg" class="error text-left">
                Please agree the terms and conditions to continue
            </div>
        </div>

        <div class="form-group">
            <textarea rows="4" class="form-control font-small terms-cond-textarea" rows="7">You must follow any policies made available to you within the Services.</textarea>
        </div>

        <div class="form-group">
            <button class="fluid yellow large ui button btn btn-block btn-warning reg-btn-submit" type="submit">Signup</button>
        </div>
    </form>

AOT Output

Thanks in advance

Vikram


It looks the JIT compiler will never check the type of mobile.errors, but AOT check it at compilation by looking this line :

<div *ngIf="mobile.errors && (mobile.dirty || mobile.touched)">

According that in this line mobile.errors is a boolean, you'll obtain your traces... I can't reproduce this bug (version problem ?), but maybe the following code will fix it :

<div *ngIf="(mobile.errors != null) && (mobile.dirty || mobile.touched)">

There is an opened issue here : https://github.com/angular/angular/issues/11425