[英]Title service in angular2
我已經使用了Angular的Tile服務,並且標題設置成功。 這是代碼:
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
@Component({
selector: 'app-homepage',
templateUrl: './homepage.component.html',
styleUrls: ['./homepage.component.css']
})
export class HomepageComponent implements OnInit {
constructor(private titleService: Title) { }
ngOnInit() {
this.titleService.setTitle('homepage first title');
}
}
但是問題是,當我通過“查看頁面源代碼”檢查標題更改時,沒有任何更改得到反映,並且索引頁面中的默認標題顯示了,我該怎么辦才能解決此問題。
“查看頁面”源是普通的index.html
源文件(就像您在服務器文件系統中擁有的一樣)。 沒有執行JavaScript或執行任何操作,因此顯然不會顯示任何內容。
如果您希望應用程序已經編譯,請查看NgUniversal ,以利用服務器端渲染。 不確定是否適合您的用例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.