相关疑难解决方法(0)

AngularJS UI路由器 - 在不重新加载状态的情况下更改URL

目前我们的项目使用默认$routeProvider,我正在使用这个"hack",url无需重新加载页面即可进行更改:

services.service('$locationEx', ['$location', '$route', '$rootScope', function($location, $route, $rootScope) {
    $location.skipReload = function () {
        var lastRoute = $route.current;
        var un = $rootScope.$on('$locationChangeSuccess', function () {
            $route.current = lastRoute;
            un();
        });
        return $location;
    };
    return $location;
}]);
Run Code Online (Sandbox Code Playgroud)

并在 controller

$locationEx.skipReload().path("/category/" + $scope.model.id).replace();
Run Code Online (Sandbox Code Playgroud)

我想到的替换routeProviderui-router筑巢路线,但无法找到这ui-router.

是否有可能 - 做同样的事情angular-ui-router

我为什么需要这个?让我用一个例子说明:
用于创建新类是路线/category/newclicking在SAVE我秀success-alert,我想改变路线/category/new,以/caterogy/23(23 -是存储在数据库新项目的ID)

angularjs angular-ui-router

128
推荐指数
5
解决办法
12万
查看次数

Angular/UI-Router - 如何在不刷新所有内容的情况下更新URL?

我是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>
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angular-ui-router

15
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular-ui-router ×2

angularjs ×2

javascript ×1