Ionic routing uses $state.go parent page to pass parameters to child pages

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

1. Routing configuration for parent pages

. State (' Tab.article ', {  URL: '/article ',  nativetransitions: {type: ' fade '  }, views  : {' tab-article ': {  templateurl: ' templates/article/article.html ',  controller: ' Articlecontroller '}}  })
2. Routing configuration for sub-pages

. State (' Tab.article_details ', {  URL: '/article_details?articledetailsurl ', views  : {' tab-article ': {  Templateurl: ' templates/article/article_details.html ',  controller: ' Articledetailscontroller '}}  )
3. Parent page Pass parameter procedure
/*** @param URL Path *///The following click event is placed in the parent page Controller $scope.itemclicked = function (URL) {//url is the parameter passed from the article.html page; The first parameter is the path to the route, the second parameter is the value assigned to the property, $state. Go (' tab.article_details ', {articledetailsurl:url});}
4. Parent page Pass parameter source
        The following label is placed on the parent page <li ng-click= "itemclicked (URL)" > click Get url</li>
5. Sub-page Get parameters
    The following JS is placed in the child page controller, the following can get the parent page passed over the URL    var articledetailsurl = $stateParams. Articledetailsurl;

If the list page jumps to the detail page, passing too many parameters, you can also use this method to pass, using the JSON string to pass, to the target interface to parse it can be:

6. HTML for parent page (List page):

<ion-item ng-repeat= "Listdata in Listdatas ng-click=" Listdetailsclick (listdata) "></ion-item>

7. Controller for parent page (List page):

$scope. Listdetailsclick = function (listdata) {        //Convert object to string        var Listdataall = Angular.tojson (listdata);        $state. Go ("ListDetails", {id:listdataall});      };

8. Controller for Sub-page (Detail page):

Converts a string to an object $scope.listdata = Angular.fromjson ($stateParams. ID);

9. Routing configuration:

. State (' ListDetails ', {          URL: '/listdetails/:id ',          templateurl: ' templates/list/listdetails/ Listdetails.html ',          controller: ' Listdetailscontroller '        });

Note: In the actual process, you need to rely on injection $state, $stateParams and other services.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.