将 html 插入 div 并保持 ui-router ui-sref 属性正常工作 [英] Insert html into div with angular keeping ui-router ui-sref property working

查看:20
本文介绍了将 html 插入 div 并保持 ui-router ui-sref 属性正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:

我有一个 div,需要从函数中注入一些 html:

I have a div which needs to get some html injected from a function:

<div ng-bind-html="myCtrl.getMyLink()"></div>

在我的控制器中,我有:

in my controller I have:

this.getMyLink = function () {
    return '<a ui-sref="app.go.to.state1">my link</a>';
}

它有效,但根本不起作用.我的 html 最后只有

It works but not at all. All I have at the end in my html is only

<a>my link</a>

这是一个链接,但 ui-sref 重定向不起作用.肯定有我遗漏的东西.

It's a link but the ui-sref redirection is not working. There is surely something I'm missing.

我该如何解决?

推荐答案

ng-bind-html 里面的内容不是由 angular 编译的,它是为静态 html 设计的.

The content inside ng-bind-html doesn't get compiled by angular, it is intended for static html.

您需要改用自己的指令,并设置模板或使用 $compile 自行编译.

You would need to use your own directive instead and either set a template or do your own compiling with $compile.

或者,您也可以使用 ng-include.没有为您的用例提供足够的详细信息,无法提供更多帮助

Alternatively you might be able to use ng-include. There aren't enough details given for your use case to help much more

这篇关于将 html 插入 div 并保持 ui-router ui-sref 属性正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆