1

I have a register form and I wish to display an error message on the form, in case something went wrong.

In my .ts file, I have the following code :-

onSubmit(email, password, name, surname, username, homephonenumber, mobilenumber){
this._userService.register(email, password, name, surname, username, homephonenumber, mobilenumber)
  .subscribe((result) => {
    if (result.success == "True") {
      //this._userService.login(email, password);
    }
    else
    {
      this.errorMessage = result.message;
    }
});

}

And in my form I have the following:-

<div class="alert alert-danger" ng-if="{{errorMessage}}"></div>

This is throwing an error in the console:-

Can't bind to 'ng-if' since it isn't a known property of 'div'

How can I get the error message to display?

Thanks for your help and time.

1 Answer 1

1

ng-if is angularjs syntax. For angular 2 change it to :

<div class="alert alert-danger" *ngIf="errorMessage"></div>

Angular 2 template docs : link

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

Comments

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.