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

半城伤御伤魂 提交于 2019-12-22 10:39:50

问题


Here is my case:

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

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

<a>my link</a>

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

How can I fix that?


回答1:


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

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

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




回答2:


ng-bind-html does not work with ui-sref directive. Just use href="path/to/state1" instead



来源:https://stackoverflow.com/questions/32222620/insert-html-into-div-with-angular-keeping-ui-router-ui-sref-property-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!