raj m
raj m

Reputation: 2023

How to add templateURL on condition from service in angular2

I have a component which has templateURL. Based on the service true or false it should load. for example first time it service with variable load = true, so templateURL should load. Next time I will set load=false. After this if I call the component again templateURL should not load. How can I achieve this. I want HTML should be remain same in second click, instead of reintialize.

Upvotes: 1

Views: 411

Answers (1)

Paresh Nagore
Paresh Nagore

Reputation: 486

Maybe you can show/hide your html div based on variable load. Supposing you have html file named mycomponent.html in templateUrl

@Component({
    templateUrl: './mycomponent.html'
})

Your html file should be something like this

<div *ngIf="load">
    ...
</div>

Upvotes: 1

Related Questions