javascript - 如何在Angular templateurl中添加变量
问题描述
我想为我的组件加载供应商特定的 html 模板。下面是一个代码片段。问题是,我将解析文本字符串作为输出而不是实际模板。有人可以帮我理解这里出了什么问题吗?
代码片段:
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() {
}
}
我得到的输出:
./vendors/helpline.google.component.html
这里 google 是来自环境文件的变量。environment.vendor_prefix
这可能不是一个重复的问题。我实际上是在尝试理解这种奇怪的行为。虽然它是一个templateUrl
,它仍然表现得像template
。在编译器命中类装饰器之前,变量值也得到解决。
解决方案
推荐阅读
- node.js - 如何使 socket.io 在 pm2 集群模式下正常工作?
- excel - 将特定列复制到另一个工作表
- android - 使用 Visual Studio 在 Flutter 上运行 Gradle 时出错
- windows - 我需要在 Ansible 中找到除一两个文件之外的所有文件
- php - 如何将数据添加到表中的现有记录
- c# - 具有通用约束的通用接口无法转换
- javascript - 指向子对象时引用整个数组的对象数组的索引
- vue.js - 如何加载 JSON 配置文件并让 Vue 应用程序等待这个?
- python - get_dummies() 用于多个 Pandas DataFrame
- php - 如何制作多语言联系表