【发布时间】:2014-01-16 11:00:40
【问题描述】:
在我开始使用 ng-include 之前,我的代码一直有效。现在,每次我转到使用此指令的页面时,我都会卡在页面上。后退按钮已停止工作,您将永远停留在同一页面的循环中。
我的网站使用 Asp.NET MVC 5 运行。
我的一些代码:
HTML“主机”
<div id="place">
<div data-ng-include="'/app/angular/views/place.html'"></div>
</div>
HTML place.html
<div>
<h1>{{place.PlaceName}}</h1>
<ul class="unstyled-list">
<li data-ng-repeat="hint in place.Hints">
<!-- more code -->
</li>
</ul>
</div>
JAVASCRIPT
$scope.place = { };
// 'maps' is a google maps plugin
maps.autoComplete({ success: function(result) {
// gets the result of the user search
History.pushState({ name: result.name, id: result.id }, result.name, '/place/' + result.id);
});
History.Adapter.bind(window, 'statechange', function () {
var state = History.getState();
// go to the server and get more info about the location
$mapService.getMetaInfo({id: state.data.id}).then(function (d) {
// get place info
$scope.place = d;
});
});
当我删除 ng-include 并将其替换为“原始”html 时,它可以正常工作。这种“无限循环”只有在添加ng-include 时才会发生。
【问题讨论】:
-
我猜你应该展示你是如何使用
ng-include指令的,如果你使用得当,你应该提供一个能重现问题的插件。 -
您应该将任何外部插件转换为 Angular 指令,将两种不同的范式混合用于 DOM 操作是不明智的。
-
我无法想象有人会这样做。如果它是一个简单的插件,我会同意你的看法,但是,任何插件......它太重了,你不觉得吗?
-
@LeCoder 实际上你不应该。 Angular Team 的目标之一是与其他工具的兼容性。我同意 Stewie 的观点 - 如果没有真正的代码,我们无法回答您的问题。由于place.html模板中的ng-include,我只能猜测无限循环。
-
你可以这样做,这样我们就可以看到路径没有任何问题.. 并用
标签: angularjs history.js