angular-ui-router views and controllers are not lo

2019-08-14 03:32发布

after I did the update to angular 1.3 I'm not able to reach the controllers and views, they simply doesn't load.

the states in my root works perfectly, this is my app.js

$stateProvider.state("root",
    {
        url: '',
        abstract: true,
        views: {
            'footer@': {
                templateUrl: "/partial/footer/footer.html",

            },
            'header@': {
                templateUrl: "/partial/header/header.html",
            }
        }
    }).state('root.home', {
            url: '/index',
            views: {
                'container@': {
                    templateUrl: '/partial/index/index.html',
                    controller: 'IndexCtrl'
                }
            }
        }
    ).state('root.welcome', {
        url: '/index/:status',
        views: {
            'container@': {
                templateUrl: '/partial/index/index.html',
                controller: 'IndexCtrl'
            }
        }
    });

an also my configuration:

$urlRouterProvider.otherwise('index');
$locationProvider.hashPrefix('!');
$locationProvider.html5Mode({ enabled: false });

by after doing a stage.go or just by typing the url, I'm not able to reach any route in these states:

$stateProvider.state("candidate",
    {
        url: '',
        abstract: true,
        views: {
            'footer@': {
                templateUrl: "/partial/footer/footer.html"
             },
            'header@': {
                templateUrl: "/user/partial/user.header/user.header.html",
            },
            'sideBar@': {
                templateUrl: '/user/partial/user.sidebar/user.sidebar.html',
                controller: 'SidebarCtrl',
                resolve: {
                    user: 'currentUser'
                }
            },
            'navBar@': {
                templateUrl: '/user/partial/navbar/navbar.html'
            }
        }
    }).state('candidate.dashboard',
    {
        url: '/dashboard',
        views: {
            'container@': {
                templateUrl: '/user/partial/user.dashboard/user.dashboard.html',
                controller: 'DashboardCtrl',
                resolve: {
                    dashboardinfo: function ($resource, tracker) {
                        var resourceGet = $resource('/user/dashboard');
                        var promise = resourceGet.get().$promise;
                        tracker.addPromise(promise);
                        return promise;
                    }
                }
            }
        }
    })

I've spent a couple of hours trying to figure this out without any luck, maybe it's just a small detail I'm missing, any advice will be more than welcome.

PS: I'm using v0.2.12-pre1

2条回答
劫难
2楼-- · 2019-08-14 03:43

it turns out that the resolve method was failing, I'm using angular promise tracker

 var resourceGet = $resource('/user/dashboard');
 var promise = resourceGet.get().$promise;
 tracker.addPromise(promise); <-- fails here
 return promise;

it seems like resources and promises have breaking changes and my implementation could be deprecated.

查看更多
SAY GOODBYE
3楼-- · 2019-08-14 03:55

I tried to replicate the issue, mentioned above in this working plunker. All the code is almost unchanged, I just used a custom version of UI-Router. The reason is this reported and known bug:

Due to: angular/angular.js@dc3de7f
the html5mode-check in urlRouter.js [line 383] is no longer correct. And thus it's impossible to disable html5mode.
A quick fix could be:

var isHtml5 = $locationProvider.html5Mode();
if (angular.isObject(isHtml5)) {
  isHtml5 = isHtml5.enabled;
}

And this (the code above) is the change I made. Nothing else. All the code started to work then...

Check also this answer

for a Chris T link to fixed version...

查看更多
登录 后发表回答