0

I'm trying to pass a message from state1 to state2 in ui-router.

looked up most of the question on here about this topic but unfortunately can't make sense of it.

This is my main code and $stateProvider :

myApp.config(function($stateProvider, $urlRouterProvider) {
  //
  // For any unmatched url, redirect to /state1
  $urlRouterProvider.otherwise("/state1");
  //
  // Now set up the states
  $stateProvider
    .state('state1', {
      url: "/state1",
      templateUrl: "state1.html"
    })
        .state('state2', {
      url: "/state2",
      templateUrl: "state2.html"
    })

});

Here is a Plunker of what i created to test this out.

What should i do to make it work? Thanks

Mojtaba
  • 733
  • 4
  • 12
  • 26
  • 1
    may be help you http://stackoverflow.com/questions/28248236/angular-ui-router-passing-data-between-states-without-url – Hadi J May 10 '16 at 06:23

1 Answers1

1

something like this

myApp.config(function($stateProvider, $urlRouterProvider) {
  //
  // For any unmatched url, redirect to /state1
  $urlRouterProvider.otherwise("/state1");
  //
  // Now set up the states
  $stateProvider
    .state('state1', {
      url: "/state1",
      templateUrl: "state1.html"
    })
        .state('state2', {
      url: "/state2/:id",
      templateUrl: "state2.html"
    })

});

or

 myApp.config(function($stateProvider, $urlRouterProvider) {
      //
      // For any unmatched url, redirect to /state1
      $urlRouterProvider.otherwise("/state1");
      //
      // Now set up the states
      $stateProvider
        .state('state1', {
          url: "/state1",
          templateUrl: "state1.html"
        })
            .state('state2', {
          url: "/state2",
          templateUrl: "state2.html",
          params: {id: ""}
        })

    });

then the ui-serf

<a ui-sref="state2({id:'value'})">Send param and go to page 2</a>

the name (id) have to be equal

Erez
  • 574
  • 1
  • 6
  • 23