Skip to content

Cannot read property '@' of null when using $state in onEnter #1434

@johannesjo

Description

@johannesjo

When using the following setup

           //Dashboard routes
            .state('dashboard', {
                abstract: true,
                url: '/dashboard',
                templateUrl: 'modules/dashboard/_layout.html'
            })
            .state('dashboard.overview', {
                url: '/cases',
                templateUrl: 'modules/dashboard/issue/issues.html',
                controller: 'IssuesCtrl',
                resolve: {
                    issues: function (Issues, $state)
                    {
                        console.log($state);

                        return Issues.query().$promise;
                    }
                },
                onEnter: function (issues, $state)
                {
                    console.log(issues, $state);

                    if (issues.length === 1) {
                        $state.go('dashboard.issue', {id: issues[0].id})
                    }
                }
            })

I get the following 2 errors

TypeError: Cannot read property '@' of null
    at updateView (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:3268:82)
    at http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:3239:11
    at Scope.$get.Scope.$broadcast (http://localhost:9000/bower_components/angular/angular.js:13790:50)
    at Object.load (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2999:22)
    at Object.injectables.$template (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2899:24)
    at Object.invoke (http://localhost:9000/bower_components/angular/angular.js:4260:27)
    at proceed (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:411:42)
    at invoke (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:407:26)
    at study (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:386:14)
    at $Resolve.resolve (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:490:34) angular.js:10629
TypeError: Cannot read property '@dashboard' of null
    at updateView (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:3268:82)
    at http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:3239:11
    at Scope.$get.Scope.$broadcast (http://localhost:9000/bower_components/angular/angular.js:13790:50)
    at Object.load (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2999:22)
    at Object.injectables.$template (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2899:24)
    at Object.invoke (http://localhost:9000/bower_components/angular/angular.js:4260:27)
    at proceed (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:411:42)
    at invoke (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:407:26)
    at study (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:386:14)
    at $Resolve.resolve (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:490:34) angular.js:10629

when trying to enter the route with issue.length being 1.

When I use return Issues.query() instead of return Issues.query().$promise the issues are not resolved inside onEnter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions