{"id":21244151,"url":"https://github.com/aaronksaunders/ionic2-ionviewcanenter-app","last_synced_at":"2026-04-17T01:02:50.282Z","repository":{"id":139352992,"uuid":"81694726","full_name":"aaronksaunders/Ionic2-ionViewCanEnter-App","owner":"aaronksaunders","description":"Ionic 2 - Using \"ionViewCanEnter\" to simulate resolve from angular 1","archived":false,"fork":false,"pushed_at":"2017-02-13T03:55:43.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T04:26:37.058Z","etag":null,"topics":["angular2","angularjs","ionic","ionic-framework","ionic2","ionviewcanenter","javascript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aaronksaunders.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-12T01:21:57.000Z","updated_at":"2017-07-24T14:19:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"ab12fd63-1167-4811-adc9-c10bf25bed0c","html_url":"https://github.com/aaronksaunders/Ionic2-ionViewCanEnter-App","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aaronksaunders/Ionic2-ionViewCanEnter-App","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2FIonic2-ionViewCanEnter-App","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2FIonic2-ionViewCanEnter-App/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2FIonic2-ionViewCanEnter-App/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2FIonic2-ionViewCanEnter-App/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronksaunders","download_url":"https://codeload.github.com/aaronksaunders/Ionic2-ionViewCanEnter-App/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2FIonic2-ionViewCanEnter-App/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31910584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"ssl_error","status_checked_at":"2026-04-16T18:21:47.142Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular2","angularjs","ionic","ionic-framework","ionic2","ionviewcanenter","javascript"],"created_at":"2024-11-21T01:17:21.691Z","updated_at":"2026-04-17T01:02:50.253Z","avatar_url":"https://github.com/aaronksaunders.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ionic2-ionViewCanEnter-App\nIonic 2 - Using \"ionViewCanEnter\" to simulate resolve from angular 1\n\n### Overview\nLooking for a way to preload data before transitioning to a page and not transitioning if an error occurs\n\n###CheckOut Video on YouTube\nhttps://youtu.be/ZWYhR4Qo0PE\n\n\n### The Code\nThis will focus on the code specific to the page transition from the `HomePage` to the `NextPage`. The `NextPage` is the page that we only want to transition to after the http request is completed and if it is completed successfully.\n\nSo in the `home.ts` we have a two functions, one for sucessfully opening the `NextPage` and one for forcing the page not to transition.\n\n```Javascript\n  showNextPageSuccess() {\n    this.navCtrl.push(NextPage, {})\n      .catch(() =\u003e {\n        console.log(\"next page loaded successfully\")\n      })\n  }\n  ```\n  \n  And for the failure, we  will pass a parameter that will tell the next page to fail\n  \n  ```Javascript\n  showNextPageFailure() {\n    this.navCtrl.push(NextPage, { 'fail': true })\n      .catch(() =\u003e {\n        console.log(\"next page DID NOT load successfully\")\n      })\n  }\n  ```\nThe magic for all of this is the `ionViewCanEnter` function from the ionic component. [See more information on the function here](https://ionicframework.com/docs/v2/api/navigation/NavController/), but this is the function we will use as a guard. This function can return a promise or true or false; when returning a promise, we wait for the promise to be resolved successfully before transitioning to the page.\n\n```Javascript\n  ionViewCanEnter() {\n    console.log(\"in ionViewCanEnter\")\n\n    return new Promise((resolve, reject) =\u003e {\n      // we will check the fail param to see what to do \n      if (this.navParams.get('fail')) {\n        reject(true) // don't load page\n      } else {\n        // we want to only transition if data is loaded, or after the\n        // data is loaded..\n\n        this.http.get('https://randomuser.me/api/?results=5')\n          .map(res =\u003e res.json().results)\n          .subscribe(\n          (res) =\u003e {\n            console.log('got my data', res)\n            this.userList = res;\n\n            // resolve the promise so the page can transition\n            resolve(res)\n          },\n          (err) =\u003e {\n            // error happened, dont transition\n            reject(err)\n          }\n          );\n      }\n    })\n  }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronksaunders%2Fionic2-ionviewcanenter-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronksaunders%2Fionic2-ionviewcanenter-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronksaunders%2Fionic2-ionviewcanenter-app/lists"}