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

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

问题描述

这是我的情况:

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



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

在我的控制器中我有:

  this.getMyLink = function(){
return'< ui-sref =app.go.to.state1>我的链接< / a>';
}

它可以工作,但根本不能。我最后在html中只有

 < a>我的链接< / a> 

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



我该如何解决这个问题?

ng-bind-html 中的内容没有通过angular进行编译,而是用于静态html。



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

可能可以使用 ng-include 。没有足够的细节给你的用例来帮助更多


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?

解决方案

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

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

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