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']
})
2
  • 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. Commented Aug 31, 2018 at 6:21
  • Possible duplicate of Angular 2 dynamic template url with string variable? Commented Aug 31, 2018 at 6:27

1 Answer 1

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.