Reputation: 167
I am trying to show a particular div based on the input field value on-load itself. the value set on the input field from my angular service. But with the [(ngModel)] it doesn't bind on load. Is there any way i can achieve this using angular 2.
<input id="showValue" value="1" [(ngModel)]="showValue">
{{showValue}}
<div class="form-group" *ngIf="show==1 || 'showValue'==1">
<h5>BACKGROUND</h5>{{showValue}}
</div>
Upvotes: 1
Views: 1734
Reputation: 3
Local storage is not a good way to do so you should user services then set values in scope variables.
Upvotes: 0
Reputation: 657048
Set instead the value of showValue
class MyComponent {
showValue:string;
constructor() {
this.showValue = 1;
}
}
<input id="showValue" [(ngModel)]="showValue">
{{showValue}}
<div class="form-group" *ngIf="show==1 || showValue==1">
<h5>BACKGROUND</h5>{{showValue}}
</div>
Upvotes: 1