简体   繁体   English

将html插入到div中,保持ui-router ui-sref属性正常工作

[英]Insert html into div with angular keeping ui-router ui-sref property working

Here is my case: 这是我的情况:

I have a div which needs to get some html injected from a function: 我有一个div需要从函数中注入一些html:

<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>';
}

It works but not at all. 它有效,但根本没有。 All I have at the end in my html is only 我在html中的所有内容都只是

<a>my link</a>

It's a link but the ui-sref redirection is not working. 它是一个链接,但ui-sref重定向不起作用。 There is surely something I'm missing. 肯定有一些我想念的东西。

How can I fix that? 我该如何解决这个问题?

ng-bind-html does not work with ui-sref directive. ng-bind-html不适用于ui-sref指令。 Just use href="path/to/state1" instead 只需使用href="path/to/state1"

The content inside ng-bind-html doesn't get compiled by angular, it is intended for static html. ng-bind-html中的内容不是由angular编译的,而是用于静态html。

You would need to use your own directive instead and either set a template or do your own compiling with $compile. 您需要使用自己的指令,并设置模板或使用$ compile进行自己的编译。

Alternatively you might be able to use ng-include . 或者,您也许可以使用ng-include There aren't enough details given for your use case to help much more 没有足够的详细信息为您的用例提供更多帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM