我使用服务动态更改标题中的内容,具体取决于我所使用的页面,但是当我将HTML放入我的组件时,它不会在浏览器中呈现(请参阅例子如下)
home.component.ts
import { Component, OnInit } from '@angular/core';
import { HeaderTitleService } from '../../services/headerTitle.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
constructor(
private headerTitleService: HeaderTitleService
) { }
ngOnInit() {
this.headerTitleService.setTitle(`
We strive to create things
<br> that are engaging, progressive
<br> & above all
<span class="highlight">
<em>innovative.</em>
</span>
`);
}
}
header.component.ts
import { Component, OnInit } from '@angular/core';
import { HeaderTitleService } from '../../../services/headerTitle.service'
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
title: any;
constructor(
private headerTitleService: HeaderTitleService
) { }
ngOnInit() {
this.headerTitleService.title.subscribe(updatedTitle => {
this.title = updatedTitle;
});
}
}
header.component.html
<h1>{{title}}</h1>
所以我试图将标题设置为一个字符串,其中包含我想要呈现的html标签,但是发生的事情是整个事情是作为一个字符串出现而不是它看起来像我曾经说过它在我的home.component.html。
有没有办法可以做到这一点?