我遇到这个问题,我不知道发生了什么:
我使用Angular,它的路由机制.
我使用Angular,它的路由机制.
所以我有一个url:
<a href="#/videos/detail/{{video.Id}}" onclick="location.reload();">
<div class="card-image">
<img ng-src="{{video.ThumbnailUrl?video.ThumbnailUrl:'img/images.png'}}" src="" />
</div>
</a>
正如你可以看到有一个onclick =“location.reload();这适用于Chrome和IE9,但在FF上,它正在执行以下操作:
>点击链接
>网址已更新
> location.reload()被称为页面被刷新
> url和角度视图,返回到点击链接的页面
>按“F5”,实际页面和网址正在加载
我也试过做了location.reload(true);因为如果也许路线缓存等等,但没有运气.
如果你想知道为什么刷新和位置:
我需要刷新一个插件的页面来重新加载(由于其中的错误),这种方法是我想到的第一个.
编辑:
最终通过将Angular和某些Jquery进行组合来完成;
所以最后的html看起来像这样;
<a href="#" class="prevent" ng-click="redirectwithreload('# />videos/detail/'+video.Id)" >
<div class="card-image">
<img ng-src="{{video.ThumbnailUrl?video.ThumbnailUrl:'img/images.png'}}" src="" />
</div>
</a>
该指令看起来像这样
.directive('videoCard',function () {
return {
restrict: 'E',templateUrl: 'partials/directives/video-card.html',controller: function ($scope,$element,$location) {
$scope.redirectWithReload = function (url) {
var toUrl = location.href.split('#')[0] + url;
location.replace(toUrl);
}
},compile: function () {
return {
post: function () {
$('a.prevent').click(function (e) {
e.preventDefault();
});
}
}
}
};
})
类防止只是为了我的Jquery来防止默认
并进行了点击,因为如果我需要添加更多的vars到url,现在很容易做到:)
感谢所有的帮助!特别是:@mplungjan
解决方法
如果您将ID存储在属性中并使用替换,则可以执行此操作
<a href="#" id="{{video.Id}}"
onclick="location.replace(location.href.split('#')[0]+'#/videos/detail/'+this.id); return false">
或者是纯粹主义者(这里是jQuery,我不做Angular):
<a href="#" class="vids" id="{{video.Id}}">
运用
$(function() {
$(".vids").on("click",function(e) {
e.preventDefault();
location.replace(location.href.split('#')[0]+'#/videos/detail/'+this.id); "
});
});
更多参数:
<a href="#" class="vids" data-id="{{video.Id}}" data-target="somewhere">
运用
$(function() {
$(".vids").on("click",function(e) {
e.preventDefault();
location.replace(location.href.split('#')[0]+'#/videos/detail/'+
$(this).data("id")+'/'+
$(this).data("target"));
});
});