0

I have different html files which should be triggered depending on a condition. However, I should be using just one typescript file for everything. Is this possible to do? Ideally, the value of templateUrl will be changed.

@Component({
  selector: 'app-profile',
  templateUrl: 'template1.component.html',
  styleUrls: ['appprofile.component.css']
})
caricature
  • 167
  • 1
  • 2
  • 11
  • The `@Component` decorator is executed before the component is instantiated, so if your plan is to change it based on your components properties, it's not possible. – sroes Aug 31 '18 at 06:21
  • Possible duplicate of [Angular 2 dynamic template url with string variable?](https://stackoverflow.com/questions/47133024/angular-2-dynamic-template-url-with-string-variable) – callback Aug 31 '18 at 06:27

1 Answers1

0

Not that I know of. The only way that comes to my mind without creating another component or dynamic component loading is to switch template fragments via *ngIf.

Jan B.
  • 6,030
  • 5
  • 32
  • 53