0

I wanted to load vendor specific html template for my component. Below is a code snippet. Problem is, I am getting resolved text string as an output instead of actual template. Can someone help me understand what's going wrong here?

Code Snippet:

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

const helplineTemplate: string = './vendors/helpline.'+environment.vendor_prefix+'.component.html';

@Component({
  selector: 'app-helpline',
  templateUrl: helplineTemplate,
  styleUrls: ['./helpline.component.css']
})
export class HelplineComponent implements OnInit {
  constructor() { }
  ngOnInit() {
  }
}

Output which I am getting:

./vendors/helpline.google.component.html

here google is variable which is coming from environment file. environment.vendor_prefix

This is probably not a duplicate question to this. I am actually trying to understand the strange behaviour. Although its a templateUrl, it is still behaving like template. Also the variable value is getting resolved before compiler hits class decorator.

Mahesh
  • 1,427
  • 2
  • 19
  • 42
  • Can you explain `I am getting resolved text string as an output instead` what that means. – Reactgular Jul 10 '19 at 11:13
  • @Reactgular, I am expecting the content inside `./vendors/helpline.google.component.html` file to get rendered on screen. However I am just getting plain text as ./vendors/helpline.google.component.html on screen. – Mahesh Jul 10 '19 at 11:16
  • Are you sure you're using `templateUrl` and not `template`? – Reactgular Jul 10 '19 at 11:19
  • yes. The code is copy pasted here as it is. – Mahesh Jul 10 '19 at 11:19

0 Answers0