html - 使用具有选择器值的变量作为字符串Angular呈现html内容
问题描述
我从上周开始研究 Angular。我正在尝试不直接使用其选择器来呈现组件,我正在将该选择器值作为某个变量中的字符串,并且我试图在 html 文件中传递该变量,但它正在将其视为字符串值而不是 html 标记。
这是我的 ts 文件,其中选择器是app-out。
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-out',
templateUrl: './out.component.html',
styleUrls: ['./out.component.scss']
})
export class OutComponent implements OnInit {
my_comp;
constructor(_TestComponent: TestComponent) {
this.my_comp = _TestComponent;
}
ngOnInit() {
console.log("hskjfhk", this.my_comp.impo)
}
}
在这里,我取了变量mySelVar的值,它的值与我的选择器相同。
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'primeng-sandbox';
mySelVar = 'app-out';
public imageObject;
ngOnInit(){
}
}
这是html,我想使用该变量呈现该组件,但我知道为什么它不将其视为选择器
<courses></courses>
<app-test></app-test>
<{{mySelVar}}>
如果我这样做,它就可以工作, <app-out></app-out>
但我想改用变量。请帮助我!
解决方案
推荐阅读
- python - 在 Raspberry Pi 3 上使用 cron 打开和关闭 USB 端口
- git - 如何在 golang 中获取当前存储库的 git 标签(或分支名称)?
- amazon-web-services - 同步传输工作时,AWS/s3 中的异步传输失败
- tensorflow - 如何使用 tensorflow 联合进行数据扩充?
- javascript - 如何将 UnityEngine.UI.Button 转换为字符串
- java - 将 for 循环转换为 hashmap 打印的方法签名
- php - 如何从 Laravel API 中的集合中返回单个对象
- java - 如何在springboot中返回一个json结果
- javascript - 使用 Leaflet 计算分数缩放
- python - 可散列、可调用数据类的 Python 类型提示