私はSEOの動的メタデータを必要とするangular4ブログアプリを持っています。 Myサービス(BlogService)は、PHPサーバーからJSONデータを配信します。例: Angular4でダイナミックメタデータを追加するには
{"ID":"168","title":"HTML Src Test","description":"testing the html thingy in angular","content":"<h1>Hello, World ... This is a heading.<\/h1>\n<p><img title=\"test\" src=\"https:\/\/i.stack.imgur.com\/ipOIT.png\" alt=\"test\" width=\"20%\" \/><\/p>\n<pre class=\"prettyprint\">code code <br \/>function(){<br \/>console.log(\"hello\");<br \/>alert(\"hello\");<br \/>}<\/pre>\n<p> <\/p>","date":"26th Apr 2017","slug":"html-src-test","imagepath":"","category":"Testy Test McTest","ttr":1,"comcount":0}
これは次に解釈され(例えば {{post.titleを}})通常の角のように表示される
BlogService:
getPost(slug: string): Promise<Post> {
const url = `${this.blogUrl}?id=${slug}`;
console.log(this.http.get(url).toPromise().then(response => response.json()));
return this.http.get(url)
.toPromise()
.then(response => response.json() as Post)
.catch(this.handleError);
}
BlogpostComponent:
ngOnInit(): void {
this.getData();
}
getData() {
this.route.params
.switchMap((params: Params) => this.service.getPost(params['slug']))
.subscribe(post => this.post = post);
}
このhttpリクエストからデータを渡してHTMLのメタタグに表示するには?
おかげ
メタタグは、メタタグのタイトルや説明よりもページ内の実際のコンテンツに焦点を当て始めたので、もはや重要ではありません。ページに適切なリンクとコンテンツがあることを確認して、あなたのURLがうまくいって読めるようにしてください。そのアンガーの宇宙以外は、残りの世話をするべきです。 – EyoelD