私はページタイトルを取って変数に書き込む必要があります。typescriptを使用してページタイトルを取得するにはどうすればよいですか?
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'home',
templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {
title: string;
ngOnInit() {
console.log("Title is " + this.title);
this.title === document.title;
}
}
をしかし、私は、コンソール上で、「タイトルが定義されていません」取得しています: 私はtypescriptですコードを使用しています。
私も試してみました:
title: string;
ngOnInit() {
this.title === this.titleService.getTitle();
console.log("Title is " + this.title);
}
public constructor(private titleService: Title) { }
getTitle() {
this.titleService.getTitle();
}
が、結果は同じです。ページタイトルを取得する正しい方法は何ですか?
を参照してください。ただし、document.titleはまだ設定していますか? – Vega
はい_Layoute.cshtmlにタイトルが設定されています。 .NETコアでこれを使用していますが、質問には関係ないと思いますか? – kendzi
'==='?単一の '= 'を使用してください。 –