将ng指令传递给Leaflet L.popup().setContent() [英] Passing ng-directive to Leaflet L.popup().setContent()

查看:589
本文介绍了将ng指令传递给Leaflet L.popup().setContent()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您提出我的问题.

目标:将Angular指令传递给L.popup()的.setContent()方法

问题:

我需要在指令上运行$ compile才能使其输入ng.但是类似

I need to run $compile on the directive in order for it to enter ng. But something like

.setContent($compile('<new_marker_form></new_marker_form'))

产生一个

Failed to execute 'appendChild' on 'Node': The new child element is null.

我敢打赌,ng正在尝试在传单实际添加任何HTML之前进行编译.

as I bet the ng is trying to compile before leaflet has actually appeneded any HTML.

不确定这是否更适合堆栈溢出.请让我知道是否应该移动它.

Not sure if this is better suited for Stack Overflow. Please let me know if I ought to move it.

推荐答案

示例中缺少结尾>,不确定是否只是问题中的错字.

The closing > is missing in your example, not sure if it is just a typo in the question.

并且您还没有将编译后的元素链接到任何范围,$compile的结果不是元素,而是链接函数.您必须通过传递要与元素绑定的作用域对象(或至少一个空对象)来调用该函数.

And you haven't linked the compiled element to any scope, the result of $compile is not an element, but a linking function. You have to call the function by passing a scope object that you want the element to bind with (or a least an empty object).

var linkFn = $compile('<new_marker_form></new_marker_form>');
var element = linkFn({}); // or pass any scope object, may be $rootScope.$new() if you do not have one.
L.popup().setContent(element[0]); // use element[0] to pass a DOM instead of jQuery/jqLite object.

或者一个班轮..

L.popup().setContent($compile('<new_marker_form></new_marker_form>')({}));

希望这会有所帮助.

这篇关于将ng指令传递给Leaflet L.popup().setContent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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