0

I am getting an issue with angular-2 while changing the condition to false. initially the div is set to 'true' later when i am changing the condition to false the total page is getting reloaded, output is coming as i expected but facing the reloading issue?

Here is my code

In html

<div class="container" *ngIf="mymenu.id === expandItem">
     <form class="form-horizontal" #myform="ngForm">
          <div class="row">
           <div class="col-md-9 input-group-md form-group">
             <input type="text" ngControl="itemname" [(ngModel)]="items.itemname" class="form-control" autocomplete="off" placeholder="Item Name">
             </div>

                <div>
                    <button type="submit" class="btn btn-success" (click)="add(mymenu);">
                        Save</button>
                </div>
            </form>
        </div>

In the component i am changing the expandItem to false.therefor in the *ngif is false the div has to hide. tried different ways,Relaoding Issue?

030
  • 10,842
  • 12
  • 78
  • 123
Sukumar MS
  • 748
  • 1
  • 11
  • 42

1 Answers1

1

In your method on the TypeScript side make sure that you return false in order to prevent the default browser behavior that you are getting. Another way is to call event.preventDefault(), but for that you'll have to pass additional parameter $event. However, just calling return false should be sufficient.

Have a look at this article on SO event.preventDefault() vs. return false

Community
  • 1
  • 1
Huske
  • 9,186
  • 2
  • 36
  • 53