我是Angular和ui路由器的新手。当某人选择模型并且我的控制器执行标准的SHOW方法时,我只想更新URL以包含模型的ID而不刷新页面,并继续使用我的原始视图。我不知道如何做到这一点?Angular/UI-Router - 如何更新URL而不刷新所有内容?
$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>
更详细的讨论我确定你已经看到了这个:http://egghead.io/lessons/angularjs-introduction-ui-router Radim的建议是好的。大多数jsfiddles,plunkers和articles已经过时了,虽然ui-router没有什么困难,但是需要一段时间才能实现,除非你找到正确的源码。 – scalaGirl
@radim:这是否真的解决了原始问题 - 即如何更新模型和URL,但不刷新视图?这是我在http://stackoverflow.com/questions/27467170/angular-ui-router-update-url-without-view-refreshes –