0
import { Component } from '@angular/core';
import { environment } from '../environments/environment';

const template = environment.production ? '../dev/dev-app.component.html' : './app.component.html';

@Component({
  selector: 'app-root',
  templateUrl: template,
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'app';
}

In the above I am trying to write a conditional variable called template which will load the view for the component.

Only I'm getting the following error:

ERROR in ./src/app/app.component.ts

Module not found: Error: Can't resolve ' template' in '/src/app'

Community
  • 1
  • 1
  • why would you want to do that? – FAISAL Aug 29 '18 at 14:58
  • Just a conditional html viewdepending on env –  Aug 29 '18 at 14:59
  • You cannot load template dynamically like that. This might help: https://stackoverflow.com/a/45377048/1791913 – FAISAL Aug 29 '18 at 15:02
  • Possible duplicate of [Angular 2/4 component with dynamic template or templateUrl](https://stackoverflow.com/questions/45376628/angular-2-4-component-with-dynamic-template-or-templateurl) – FAISAL Aug 29 '18 at 15:02

0 Answers0