我对Angular和ui-router都不熟悉。当有人选择一个模型并且我的控制器执行标准的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>