Sercan
Sercan

Reputation: 121

How can I change states in Angular?

I m new at Angular so please forgive me for this question. But i didnt find a way to solve it. I have two main states and these states has child states.

$stateProvider

    .state('login', {
    url: "/login",
    abstract: true,
    templateUrl: "views/login.html"
})

.state('login.intro', {
    url: "/intro",
    views: {
        'menuContent': {
            templateUrl: "views/intro.html",
            controller: "introController"
        }
    }
})

.state('app', {
    url: "/app",
    abstract: true,
    templateUrl: "views/menu.html"
})

.state('app.main', {
    url: "/main",
    views: {
        'menuContent': {
            templateUrl: "views/main.html",
            controller: "MainController"
        }
    }
})

I m trying redirect to app.main state when i m in login.intro state with this code.

$scope.startApp = function () {
    $state.go('/app/main');
};

But i m getting this error

Error: Could not resolve '/app/main' from state 'login.intro' at Object.transitionTo

So can you help me to fix this problem please ?

Upvotes: 1

Views: 954

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

$state.go() expects the name of a state:

$state.go('app.main');

Upvotes: 5

Related Questions