我是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 –