0

Could you please tell me how to send data from one view to another using state. I don't want to use factory or service. I need to send the data using url and get the data from url and display it on view. I have one field name in my first View. I want to display on the second view whatever user enters in the input field. On button click, I need to send it to another view. I am able to go to the next view but how to send the data?

Plunker http://plnkr.co/edit/iDlzhzkz0pJKN2f2CZZe?p=preview

var loginCntrl = function($scope, $location, $state) {
  $scope.testClick = function() {
    $state.go("navigation2");
  }

  $scope.name = "";

  /*$scope.fullname = function() {
    return $scope.firstname + $scope.lastname;
  };*/
}
rohanagarwal
  • 771
  • 9
  • 30
user944513
  • 12,247
  • 49
  • 168
  • 318

1 Answers1

0

$state.go can have a parameters object to pass on to the view

Check here: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options

$state.go("State", {Hello:"Hi!"});

You can then pick up those params on the view controller using $stateParams

app.controller("SomeController", function($scope, $stateParams){
    $scope.NewHello = $stateParams.Hello;
})

You will also need to amend the URL to accept this parameter:

url:"/someurl/{Hello}
Ash
  • 610
  • 4
  • 9
  • Sorry I forgot to mention that you will need to provide the state params in the URL parameter. In this case "/no/{Hello}". I've amended your Plunker here: http://plnkr.co/edit/GVrYtoBNBKb7xjQioQke?p=preview – Ash Jan 13 '15 at 10:05
  • Thanks It works ..If I need to send two parameter how i will send like "world" also – user944513 Jan 13 '15 at 10:13
  • could you please tell me how I will send multiple parameters – user944513 Jan 13 '15 at 10:17
  • Add it on to the end of the URL property and use it as you would any other state param. In this case "/No/{Hello}{World}". Here you go: http://plnkr.co/edit/cIZtDlghzAyAahxzcIdy?p=preview – Ash Jan 13 '15 at 10:18