Angular / UI-Router-如何在不刷新所有内容的情况下更新URL?
我是Angular和ui路由器的新手。当某人选择一个模型并且我的控制器执行标准的SHOW方法时,我只想更新URL以包括模型的ID,而无需刷新页面,然后继续原始视图。我不确定该怎么做…
$stateProvider .state('citylist', {
url: "/",
templateUrl: "views/index.html"
})
.state('cityshow', {
url: "/city/:id",
templateUrl: "views/index.html"
})
angular.module('app.system').controller('IndexController', ['$scope', 'Global', 'Cities', '$stateParams', '$location', function ($scope, Cities, $stateParams, $location) {
$scope.loadTown = function(id) {
Cities.get({id: id }, function(city) {
$scope.city = city
// Change URL
// Do things within the same view...
});
};
});
<button ng-click="loadTown(123456)">Chicago</button>
回答:
您使用的代码段与正确的 ui路由器 设置有点不同。我会建议您,检查此演示应用程序:http : //angular-ui.github.io/ui-
router/sample/#/contacts/1。在这里我们可以看到在不更改任何页面的情况下更改 明细的 同时 列表 是如何“固定”的。 __
此示例的代码在此处https://github.com/angular-ui/ui-
router/tree/master/sample下载。
这个代码片段( ) 应该对理解如何 _(
维基百科除外)_有很大帮助。加载演示,通读此注释说明。并且会有意义的… ui-router
以上是 Angular / UI-Router-如何在不刷新所有内容的情况下更新URL? 的全部内容, 来源链接: utcz.com/qa/404161.html