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

 往事如烟zhang_214 发布于 2023-02-10 14:55

我是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...
        });
    };
});


Radim Köhler.. 6

您使用的代码段与正确的ui-router设置相差甚远.我建议你查看这个演示应用程序:http://angular-ui.github.io/ui-router/sample/#/contacts/1.在这里,我们可以看到如何在没有任何页面刷新的情况下更改细节时如何"修复" 列表.

这个例子的代码在这里下载https://github.com/angular-ui/ui-router/tree/master/sample.

什么应该有很多帮助理解如何(除了维基)是这段代码片段:state.js.加载演示,阅读此注释说明.并且ui-router会有意义......

1 个回答
  • 您使用的代码段与正确的ui-router设置相差甚远.我建议你查看这个演示应用程序:http://angular-ui.github.io/ui-router/sample/#/contacts/1.在这里,我们可以看到如何在没有任何页面刷新的情况下更改细节时如何"修复" 列表.

    这个例子的代码在这里下载https://github.com/angular-ui/ui-router/tree/master/sample.

    什么应该有很多帮助理解如何(除了维基)是这段代码片段:state.js.加载演示,阅读此注释说明.并且ui-router会有意义......

    2023-02-10 14:58 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有