angular-ui-router views and controllers are not loading after upgrading to angular 1.3

為{幸葍}努か 提交于 2019-12-11 09:38:34

问题


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


回答1:


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:

  • Impossible to disable html5Mode with angular 1.3.0-rc.3 #1397 (small cite:)

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

  • ui-router not producing correct href attribute in angular

for a Chris T link to fixed version...




回答2:


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.



来源:https://stackoverflow.com/questions/26857023/angular-ui-router-views-and-controllers-are-not-loading-after-upgrading-to-angul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!