0

I have made yoman angular fullstack app setup.

I am making use of ui.router in application.

I have defined state parameters as

.state('tour', {
    url: '/tour',
    templateUrl: 'app/tour/tour.html',
    controller: 'tourCtrl',
    params : {tourName: null, },
  })

I am able to pass parameter to this state within application.

when my application goes to external link.

I want to get back to one of the state of my angular application with some parameter. so how can i do that??

Please Help me to do that .. Thanks

  • append those parameters into your URL, form that URL, and navigate to that URL. you can re-write your URL as /tour/:tourName ... And add a resolve... – ShivangiBilora Sep 28 '15 at 07:15
  • suppose i'm running it on my local system. i have url as localhost:9000 then i supposed to do as localhost:9000/tour/America it is correct or wrong – bhavesh gujar Sep 28 '15 at 07:25
  • it doesn't matter whether you run it locally, or on the server. If you have a state linked to a particular URL, the Url would always take you to that state. And the Url is perfectly correct. And you can access the value= "America" in $stateParams. – ShivangiBilora Sep 28 '15 at 07:30
  • http://localhost:9000/tour/tourName:AustraliaNewZealand this is the url i'm trying to hit is it correct or not... while i have designed stateparams as tourName – bhavesh gujar Sep 28 '15 at 08:31
  • change the url to tour/:tourName, and StateParams= { tourName : "AustriaNewZealand"}. Then its perfectly correct. And yes, add resolve: tourName. – ShivangiBilora Sep 28 '15 at 08:50

1 Answers1

0

you can pass parameters and maintain states using stateParams, and then maintaining them in the URL. For your understanding, I have added a plunk:

http://plnkr.co/edit/SDOcGS?p=preview

Observe the console whenever you navigate to Route1 tab, and then observe the code:

    .state('route1', {
        url: "/route1/:place",
        params: {
          place: null
        },
        views: {
            "viewA": {
                template: "route1.viewA"
            },
            "viewB": {
                template: "route1.viewB"
            }
        },
        resolve :{
          place: function($stateParams){
            console.log($stateParams);
            console.log("url", window.location);
            return $stateParams.place;
          }
        }
    })

Try this on localhost. It would work the same way on localhost, or any place where its hosted.

ShivangiBilora
  • 2,912
  • 4
  • 20
  • 27
  • should i have to do like this http://localhost:9000/tour/:StateParams=%20%7B%20tourName%20:%20%22AustriaNewZealand%22%7D. – bhavesh gujar Sep 28 '15 at 10:29
  • @bhaveshgujar: yes. Did you understand the plunk I attached? – ShivangiBilora Sep 28 '15 at 10:31
  • Could you attach a working copy of your code, so , we can figure out what's happening? – ShivangiBilora Sep 28 '15 at 10:35
  • i made go through it but not able to work out it with my system ... i my system i'm passing stateparams using ui-sref but how can send same through external system. – bhavesh gujar Sep 28 '15 at 10:38
  • i have used $state.go('booking',{room:data,tourData:{ date:$scope.showDate, code:$scope.items.code, }}) how can i do same thing from external application – bhavesh gujar Sep 28 '15 at 10:46
  • you don't need to pass those stateParams through external application. From there, you can navigate to your web-app, to a particular URL, something like, localhost:8000/tour/:booking/:room/:tourData. – ShivangiBilora Sep 28 '15 at 11:08
  • ok i'm able to pass single param but how can i pass muliple in same way – bhavesh gujar Sep 28 '15 at 12:17
  • @bhaveshgujar: you can pass as many parameters as you want. just append them to the URL, and when you are passing, pass an object, like {city: Delhi, country:India, state: Delhi}. and change your url to localhost:9000/booking/:city/:state/:country – ShivangiBilora Sep 28 '15 at 12:20