0

I am using MEANstack. Here is the simple stateparams that returns the empty object. Code :

route.js

var app = angular.module('mean-blog.home', [
'ui.router']);

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

                .state('organizers', {
            url: '/organizers',
            templateUrl: '/home/templates/organizers.html',
            controller: 'OrganizerCtrl'
        })
                .state('viewprofile', {
            url: '/vieworganizer/:organizerid',
            templateUrl: '/home/templates/viewprofile.html',
            controller: 'viewProfileCtrl'
        })
    $urlRouterProvider.otherwise("/");
});

controller.js

.controller('viewProfileCtrl', function($scope, Users, $stateParams) {
    console.log($stateParams) //returns empty object
})

View File

 <p> {{organizer._id}}</p>
  <a ui-sref="vieworganizer({organizerid:organizer._id})">
      <i class="fa fa-edit"></i>Edit
</a>

This ui-sref is also giving me the following error.

Error: Could not resolve 'vieworganizer' from state ''
transitionTo@https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js:3140:17
go@https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js:3068:14
link/</transition<@https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js:4181:13
f/l<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:138:473
e@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:40:72
nf/n.defer/c<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:44:155

If i open the direct url

http://localhost:3000/vieworganizer/59b8c14ebed9a011bc5acb54

it returns empty stateparams object.

Anyone who can help me to solve this issue!

2
  • Your state is called viewprofile not vieworganizer Commented Sep 13, 2017 at 8:34
  • You don't appear to be injecting $stateParams. Shouldn't it be .controller('viewProfileCtrl', ['$scope', 'Users', '$stateParams', function($scope, Users, $stateParams) { .... Commented Sep 13, 2017 at 8:42

2 Answers 2

0

You do not have a state named vieworganizer , it should be

<a ui-sref="viewprofile ({organizerid:organizer._id})">
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks,1 issue has been solved. another one is empty stateparams.. Will you help me on this please
change it as <a ui-sref="viewprofile ({organizerid:'organizer._id'})">
Error: Could not resolve 'vieworganizer' from state '' issue has been solved as the state name was different. Now the issue is, I am not able to get stateparams value in controller as it returns empty object.
adding quotes changes its type to string and not able to get variable data, so again empty object and not able to get id as it acts as a string
did you see if its actually getting the data?
|
0

You need to update the view file

<p> {{organizer._id}}</p>
  <a ui-sref="viewprofile({organizerid:organizer._id})">
      <i class="fa fa-edit"></i>Edit
</a>

viewprofile is the state which is defined in app.config file for url /vieworganizer/:organizerid

2 Comments

solution for empty stateparams?
have you tried the $scope.params instead of $stateParams for getting the parameters?

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.