如果我使用 Angular 编译一些 HTML,如何用编译后的 HTML 替换 DOM 元素的内容?示例:
var html = "<div>{{msg}}</div>";
var scope = $scope.$new();
var scope.msg = "Hello World!";
var linkFn = $compile(html);
var contents = linkFn(scope);
element.replaceContents(contents);//what is the actual syntax for this?
最佳答案
您想要从元素中删除内容并附加新编译的内容。
element.empty().append(contents)
关于javascript - 如何用一些已编译的 HTML 替换元素的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36992688/