1
こんにちは私は、再利用可能な関数を構築するためにトリヤンを使用していますが、何らかのコンテンツをサニタイズしていますが、DomSanitizer
というコールを呼び出すことはできません。ここ は私の関数である。それを使用する関数内でのDomSanitizerの使用方法
export function PostFormat(post){
let sanitizer: DomSanitizer; // TODO!
post['title'] = sanitizer.bypassSecurityTrustHtml(post['title']['rendered']);
post['author'] = post['_embedded']['author'][0];
post['content'] = sanitizer.bypassSecurityTrustHtml(post['content']['rendered']);
post['excerpt'] = sanitizer.bypassSecurityTrustHtml(post['excerpt']['rendered']);
if (post['_embedded']['wp:featuredmedia']){
if (post['_embedded']['wp:featuredmedia'][0]['media_details']){
post['featured_image'] = post['_embedded']['wp:featuredmedia'][0]['media_details']['sizes'][this.default_size]['source_url'];
}
}
if (post['_embedded']['replies']){
post['comments'] = post['_embedded']['replies'][0];
}
return post;
}
サービスクラスで関数をラップするだけで、簡単に 'DomSanitizer'を注入できます。 Angularと対戦しようとしないで、それははるかに楽しいでしょう。 –
hahaha @GünterZöchbauerヒントのおかげで – efirvida