Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS transition to abstract state

I'm working on an application built with AngularJS that has two different states:

  1. App intro wizard
  2. App pages (with a Navigation template and nested views)

I want to default to State 1 the first time someone access the app, once done the wizard, continue on to the App pages, State 2.

My "app" state (State 2) is an abstract state because it has nested views. So I cannot transition to this state.

.config(function($stateProvider, $urlRouterProvider) {
$stateProvider

  .state('intro', {
    url: '/',
    templateUrl: 'templates/intro.html',
    controller: 'IntroCtrl'
  })

  .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
  })

  .state('app.playlists', {
    url: "/playlists",
    views: {
      'menuContent' :{
        templateUrl: "templates/playlists.html",
        controller: 'PlaylistsCtrl'
      }
    }
  });

  $urlRouterProvider.otherwise("/");

})
like image 220
Mark Kamyszek Avatar asked Apr 04 '14 17:04

Mark Kamyszek


2 Answers

I've got the same problem as you, here is a post about abstract state: angularjs ui-router default child state and ui-sref

It explains why you can't directly access abstract state

Hope it helps.

like image 101
Neaped Avatar answered Oct 23 '22 10:10

Neaped


I have added $location service to the controller of the "intro" page and use the following to transit to app state which works for me.

$location.path('app/playlists');

The menu.html is loaded and navigated to playlists.

like image 39
Yang Zhang Avatar answered Oct 23 '22 10:10

Yang Zhang