在我的角度4应用程序中,我有一个字符串
comment: string;
comment = "<p><em><strong>abc</strong></em></p>";
Run Code Online (Sandbox Code Playgroud)
当我在我的HTML中提供这个文本时,就像
{{comment}}
Run Code Online (Sandbox Code Playgroud)
然后它显示:
<p><em><strong>abc</strong></em></p>
Run Code Online (Sandbox Code Playgroud)
但我需要以粗体和斜体形式显示文本"abc",如 abc
我怎样才能做到这一点?
我一直在寻找一种方法来启用标准的[href]链接,以便在动态加载到[innerHTML]时充当routerLinks.它似乎不是标准的东西,我找不到任何我需要的东西.
我有一个可行的解决方案,但想知道是否有人知道有任何更好的方法来做到这一点或任何潜在的问题,我可能会这样做.
我在app-routing.module.ts中使用jQuery,所以我声明了变量:
declare var $:any;
Run Code Online (Sandbox Code Playgroud)
然后我找到所有具有href属性但没有routerlink属性的锚点.然后我可以获取路径名并告诉路由器在点击时导航到它.
$(document).on('click', `a[href]:not("a[routerlink]"):not("a[href^='mailto:']"):not("a[href^='tel:']")`, function(e){
if(location.hostname === this.hostname || !this.hostname.length){
e.preventDefault();
router.navigate([this.pathname]);
}
});
Run Code Online (Sandbox Code Playgroud)
这似乎做了这个工作,但我认为必须有一个更"'角度'的方式这样做......