【问题标题】:How correct change route controller?如何正确更改路由控制器?
【发布时间】:2015-10-08 19:35:42
【问题描述】:

我有简单的表格页面(带有控制器)和像ng-controller="messageGridCtrl" ng-init="init()" 这样的初始化方法,并使用不同的控制器创建页面。

创建页面有类似<a href="#/messageTemplates">Back to list</a> 的返回链接,当我单击路由更改并调用初始化方法时,但请求不起作用(不接收到服务器)。 如果我只是重新加载(通过 f5)一切正常。

我是 angularjs 新手。

【问题讨论】:

  • 你能分享任何相关的源代码以及任何服务器路由吗?

标签: javascript angularjs


【解决方案1】:

来自the angular-route-segment documentation

$routeSegmentProvider.

when('/section1',          's1.home').
when('/section1/prefs',    's1.prefs').
when('/section1/:id',      's1.itemInfo.overview').
when('/section1/:id/edit', 's1.itemInfo.edit').
when('/section2',          's2').

segment('s1', {
    templateUrl: 'templates/section1.html',
    controller: MainCtrl}).

within().

    segment('home', {
        templateUrl: 'templates/section1/home.html'}).

    segment('itemInfo', {
        templateUrl: 'templates/section1/item.html',
        controller: Section1ItemCtrl,
        dependencies: ['id']}).

    within().

        segment('overview', {
            templateUrl: 'templates/section1/item/overview.html'}).

        segment('edit', {
             templateUrl: 'templates/section1/item/edit.html'}).

        up().

    segment('prefs', {
        templateUrl: 'templates/section1/prefs.html'}).

    up().

segment('s2', {
    templateUrl: 'templates/section2.html',
    controller: MainCtrl});

也许对你有帮助

http://scotch.io/tutorials/javascript/angularjs-multi-step-form-using-ui-router

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多