【发布时间】:2015-05-31 11:59:44
【问题描述】:
我已升级到 Angular 1.3.15,但以下代码无法正常工作:
var newScope = $scope.$new();
angular.extend(newScope, data);
var html = '<ng-include src=\'"' + templateUrl + '"\'></ng-include>';
var newHtml = $compile(html)(newScope);
在$compile之后,newHtml的数据是data: " ngInclude: undefined "。
我尝试查看 1.2 或 1.3 中可能存在的重大更改,但没有发现任何相关内容。
想法?
[编辑]
在线阅读更多示例后,例如这里:https://github.com/angular/angular.js/issues/4505
我看到当我使用旧 AngularJS 版本运行此代码时,我得到一个返回元素 ng-include.ng-scope,而使用新版本我得到 comment。
如果它添加了 2 个元素——comment 和 ng-include,这将是有意义的,但它没有,只是评论。
不知道如何从这里继续
【问题讨论】:
-
我不知道这是否相关,但是为什么您的
templateUrl周围需要单引号和双引号? -
表示这是我目录中的路径,而不是完整路径或 Web url。顺便说一句,这段代码在 Angular 1.1 上效果很好
-
我想你错过了用引号括起来的 templateUrl,比如
src="'myPartialTemplate.html'" -
放纵我。试试
var html = '<ng-include src="' + templateUrl + '"></ng-include>'; -
它解析为:
<ng-include src='"partials/geo/popups/click/marker-InstagramPost.html"'></ng-include>@yarons 会很乐意放纵。试过了,效果还是一样。