嗨,我正在尝试构建一个可重用的函数,并清理一些内容,但我不知道怎么称呼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;
}