Ela Buwa
Ela Buwa

Reputation: 1704

Angular stateprovider always hits 'otherwise' state

I'm trying to set the state through a controller while parsing 1 parameter. From what I can gather, the preferred state is called, however the "otherwise" state is loaded immediately afterwards. I discovered that preferred state was being called by hitting the back button. When the back button is clicked, the preferred state was called. Seems like a small issue in my stateprovider settings but I simply can't manage to find it.

Below is part of my controller.js file.

.controller('resultsCtrl', ['$scope', '$stateParams', 'searchfactory', '$state',
function ($scope, $stateParams, searchfactory, $state) {
    $scope.results = searchfactory.getresults();
    console.log($scope.results);
    $scope.showdoc = function(docid){
        console.log(docid);
        $state.go('doctor', { docid: docid });
    }
}])

.controller('doctorCtrl', ['$scope', '$stateParams', 
function ($scope, $stateParams) {
    alert($stateParams.docid);

}])

Below is my routes file handling the "doctor" part.

.state('doctor', {
    url: '/doctor/{docid}',
    templateUrl: 'templates/doctor.html',
    controller: 'doctorCtrl'
  })

Upon hitting the back button, the url is shown as http://192.168.8.100:8100/#/doctor/11 which I think is the proper url. Also, the alert pops up as well. the redirection is done after the "ok" button is clicked on the alert.

Your help is greatly appreciated.

Upvotes: 0

Views: 42

Answers (1)

Saurabh Agrawal
Saurabh Agrawal

Reputation: 7739

Check if templates/doctor.html exist or there is href their.

Upvotes: 0

Related Questions