【问题标题】:Update url based on model state根据模型状态更新 url
【发布时间】:2015-01-16 08:09:15
【问题描述】:

我有一个基本的 Angular 应用程序,它列出了一天中的事件。用户可以通过单击日历(angular-ui-calendar)来更改日期。在我的控制器中,我有一个 Date 类型的模型对象“selectedDay”。

目前应用的网址是: http://localhost/app#/daypicker

我已将 ngroute 配置为也接受以下形式的 url http://localhost/app#/daypicker/2015-02-15

这很好用,但我希望在用户单击日历时更新 url 并匹配我的模型对象。

因此,如果用户在日历中单击 3 月 1 日,我希望使用这个新日期更新 url。 (http://localhost/app#/daypicker/2015-03-01)

这可以通过 ngroute 完成还是我需要使用其他插件?

【问题讨论】:

    标签: angularjs ngroute


    【解决方案1】:

    查看 $routeParams 文档here

    更改您的路线网址以接受“getDate”参数或类似的内容

    /when("/daypicker/:getDate?",...)
    

    那个?将其标识为可选参数。

    将 $routeParams 注入控制器路由并使用它来读取参数。

    app.controller("daypickerController", function($scope, $routeParams){
       alert($routeParams.getDate);
    })
    

    然后,每当您的用户更改日期时,请致电

    $location.path('/daypicker/' + date);
    

    其中 date 是表示日期的字符串。 IE。 16-01-2015

    【讨论】:

      猜你喜欢
      • 2018-05-24
      • 1970-01-01
      • 2021-12-09
      • 2013-10-11
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多