简体   繁体   中英

ionic - send data from one page to another

I'm new to ionic and I need help with passing data from one view to another. I am showing data in a ionic view like this:

<table ng-repeat="x in guestlist">
    <tr> 
        <td>{{x.name}}</td>
        <td>{{x.employeeid}}</td>
        <td>{{x.phonenumber}}</td>
    </tr>
</table>

Now, if I click on any individual row, I want to pass those three values in a form, which is in different view and different controller. Can someone guide me with this?

You can use AngularJs service to pass values from one controller to another. I included a sample code. Hope your will able get an idea from it. When click on row value set those value to employee object then pass it to service. Then you can access that employee object from second controller using that service.

 var app = angular.module('yourAppName', []); app.controller('firstCtrl', function($scope, yourService) { /*Set employee data to service*/ yourService.employee = $scope.employee; }); app.controller('secondCtrl', function($scope, yourService) { /*Get employee data from service*/ var employee = yourService.employee; }); app.factory('yourService', function() { var employee = null; return { employee: employee } });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM