简体   繁体   English

无法在弹出窗口中渲染angularjs模板

[英]Unable to render an angularjs template inside a popover

I am trying to get a popover show some html content (it could be angularjs compiled content) and when I click on my "View" link, I do not see my custom directive getting processed and showing correctly (all other content is rendering okay including one that has an ng-repeat inside it suggesting that angularjs saw my angular content right) 我正在尝试使弹出窗口显示一些html内容(可能是angularjs编译的内容),并且当我单击“查看”链接时,我看不到自定义指令已得到处理并正确显示(所有其他内容都可以呈现,包括里面有一个ng-repeat的代码,表明angularjs看到我的角度内容正确)

http://plnkr.co/edit/Jy8Qlp1rsghwj4NNF2Dn?p=preview http://plnkr.co/edit/Jy8Qlp1rsghwj4NNF2Dn?p=preview

<div ng-controller="ChordCtrl">
    <chord-layout chord-matrix="{{matrix}}">
       <div id="chordLayoutHolder"></div>
    </chord-layout> 
</div>

There is a lot going on in this plunkr but the bottom line is when I click on any of the "View" inside the table, I expect dynamic contents of report1.html to show up in my tooltip - Clearly all the other contents show up but it somehow failed to do my complex chord layout rendering - The chord layout diagram rendering is tested independently in another plunkr - http://plnkr.co/edit/q5DDdKHs11OuW6SfLtTG?p=preview 这个插件有很多事情要做,但最重要的是当我单击表内的任何“视图”时,我希望report1.html的动态内容会显示在我的工具提示中-显然所有其他内容都会显示但它在某种程度上没有做到我复杂的和弦布局渲染-弦布局图呈现在另一个plunkr独立测试- http://plnkr.co/edit/q5DDdKHs11OuW6SfLtTG?p=preview

Any help in determining why my chord layout chart is not rendering would be helpful. 确定我的和弦布局图为何不呈现的任何帮助都将有所帮助。

Regards 问候

You're having issues because you're using id for your chordLayoutHolder. 您遇到了问题,因为您将id用于chordLayoutHolder。 To be honest, I'm not sure why this is an issue. 老实说,我不知道为什么这是一个问题。 Perhaps Angular pre-compiles the template and clones it, such that the id is no longer unique. 也许Angular会预先编译模板并对其进行克隆,以使id不再是唯一的。 I would be curious to know. 我很想知道。

In any case, remove <div id="chordLayoutHolder"></div> and just append to the directive element: 无论如何,都删除<div id="chordLayoutHolder"></div>并将其追加到指令元素:

<chord-layout chord-matrix="{{matrix}}">
</chord-layout>

Then, in your directive, change the following lines (that refer to chordLayoutHolder): 然后,在您的指令中,更改以下几行(引用chordLayoutHolder):

$("#chordLayoutHolder").empty();
var svg = d3.select("#chordLayoutHolder")
...

to: 至:

element.empty();
var domElement = angular.element(element)[0];
var svg = d3.select(domElement)
...

to append to the element itself, rather than another placeholder. 附加到元素本身,而不是另一个占位符。

Then it would work. 然后它将起作用。 Here's the plunker . 这是pl子

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

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