【问题标题】:ng-include is displayed as a commentng-include 显示为注释
【发布时间】:2016-09-18 02:21:45
【问题描述】:

我正在尝试在谷歌地图信息窗口中添加一个模板,但是当我尝试编译内容并将其设置为 infowindow.content 时,它会显示为评论。我正在使用版本1.2.27

var infowindow = new google.maps.InfoWindow();
var content = '<div id="iw_c" ng-include="\'/infowindow.html\'"></div>';
var compiled = $compile(content)(scope);
infowindow.setContent(compiled[0]);
console.log(infowindow.content);

这是console.log(infowindow.content)的输出

<!-- ngInclude: '/infowindow.html' -->

已经尝试过this question中的解决方案。

【问题讨论】:

  • 您需要将路径用单引号括起来。试试这个&lt;div ng-include src="'infowindow.html'"&gt;&lt;/div&gt;
  • (\) 是从内容(') 中转义(')。但即使我输入'&lt;div ng-include=""&gt;&lt;/div&gt;',我也会得到相同的输出。
  • 问题出在版本上。在 1.1.5 中工作正常

标签: angularjs


【解决方案1】:

不知道为什么,但是在 ng-include div 之前放置一个 div 解决了问题。

var infowindow = new google.maps.InfoWindow();
var content = '<div><div id="iw_c" ng-include="\'/infowindow.html\'"></div></div>';
var compiled = $compile(content)(scope);
infowindow.setContent(compiled[0]);
console.log(infowindow.content);

【讨论】:

    猜你喜欢
    • 2014-08-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 2015-02-12
    • 2014-10-29
    • 2015-05-27
    • 1970-01-01
    相关资源
    最近更新 更多