0

I have an app with multiple states that each have nested views. The one state has a conditional templateUrl, and based on a $state.param will show specific HTML/JS. I want to set a query on the URL of the state, so that I know which list item is being looked at when I click it. I cannot figure out how to set a url query and transition to the desired state's view.

My states:

 .state('index', {
        url: '/',
        views: {
            '@' : {
                templateUrl: 'views/layout.html'
            },
            'top@index' : {
                templateUrl: 'views/top.html',
                controller: function($scope, $state) {
                    $scope.logOut = function() {
                        $state.go('login');
                    };
                }
            },
            'left@index' : { templateUrl: 'views/left.html' },
            'main@index' : { templateUrl: 'views/main.html' }
        }
    })
    .state('index.list', {
        url: 'list?item',
        templateUrl: 'views/lists/list.html',
        controller: 'ListCtrl'
    })
    .state('index.list.details', {
        url: '/',
        params: {
            detail: 'overview'
        },
        controller: ctrl,
        views: {
            'details@index' : {
                templateUrl: function($stateParams) {
                    if($stateParams.detail === 'status' ) {
                        ctrl = 'StatusCtrl';
                        return 'views/details/status.html';
                    } else if ($stateParams.detail === 'overview') {
                        ctrl = 'OverviewCtrl';
                        return 'views/details/overview.html';
                    }
                }
            }
        },
    })

In my controller for the index.list, this is where I have the list and click and populate the details view.

HTML & Js:

<div class="channel" ng-repeat="item in items" ng-click="viewListDetails(item)">

$scope.viewListDetails = function(item) {
    $location.search('item', item.id);
    $state.go('index.list.details', {detail: 'status'}, {reload: true})
};

My JS above runs the through the function however it does nothing! It will not set the query or transition to the desired view for that sate.

Any help is appreciated!

3
  • do you have any errors in the console? Commented Feb 3, 2016 at 20:14
  • @koox00 no, no errors at all!! Commented Feb 3, 2016 at 20:18
  • put this in the application.run => $rootScope.$on("$stateChangeError", console.log.bind(console)); to log transition errors, maybe it fails silently. Commented Feb 3, 2016 at 20:27

1 Answer 1

0

index.deviceList.detail is not a defined state. You probably intended to write index.list.details.

Sign up to request clarification or add additional context in comments.

2 Comments

Whoops that's my typo in copy and paste into stack overflow, thanks for pointing that out.
You should debug your code and see what templateUrl return when you click, or event if the function is even called at all. Also those ctrl = 'OverviewCtrl'; looks not right, as ctrl is not defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.