【发布时间】:2018-09-29 16:02:01
【问题描述】:
我有一个函数可以从文件中获取 html 内容作为字符串。之后我把它做成了一个 html 对象。我可以在控制台中清楚地看到它有效。如何将它从服务传递到 div 元素?
nav.service.ts:
html: string;
public getZipFileContent(urlPath:string, pathInZip:string, ) {
getFileContentFromRemoteZip(urlPath, pathInZip, (content) => {
console.log(content);
let html = content;
let htmlObject = document.createElement('div');
htmlObject.innerHTML = html;
console.log(htmlObject);
this.html = html; // it's a string
this.html = htmlObject // error : can't asign string as HTMLdivElement
});
}
}
我现在通过在我的组件中添加 {{navSrv.html}} 得到什么:
我想得到什么:
你好
Console.log 来自:console.log(htmlObject);
如何获取htmlObject并将其用作变量?
【问题讨论】:
-
Angular HTML binding的可能重复
标签: javascript angular typescript javascript-objects