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

查看:36
本文介绍了将 ng-directive 传递给 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.

不确定这是否更适合 Stack Overflow.如果我应该移动它,请告诉我.

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-directive 传递给 Leaflet L.popup().setContent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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