$http({
method: 'GET',
url: 'http://localhost:55090/login/login',
}).success(function(data){
// With the data succesfully returned, call our callback
$("html").html("");
debugger
$("html").html(data);
window.history.pushState("object or string", "Title", "/login/login");
}).error(function(){
alert("error");
});
上面的代码正在工作,我能够加载另一个页面的数据而无需刷新,但问题是我对两个页面使用两个不同的 Angular 。 一旦我加载另一个 html,所有功能(包括模型、指令)就停止工作。
最佳答案
如果您有 2 个不同的页面,第二个页面可能会使用 ng-app 属性创建自己的 Angular 注入(inject)器。所以你不会有第一页的服务/ Controller 。
Angular 是单页应用程序,不能像这样与 jQuery 一起使用。如果您想在网络上执行一些导航检查 ngRoute
或 ui-router
。
如果您需要在特定位置添加一些 HTML,请检查 $compile
和 angular.element
,即使不推荐这样做。
关于javascript - Angular Controller 在 window.history.pushstate 之后不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36857387/