Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    IONIC HELP

    Hybrid App Development
    ionic5 angular typescript
    3
    6
    531
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • oditha
      oditha Web Development last edited by

      Ionic වල පොඩි දෙයක් දැනගන්න ඕන.

      1. Storage eke තියෙන ඩේටා ටිකක් API එකට pass කරලා. API response එකෙ එන ඩේටා ඇප් එකේ පාවිච්චි කරන්න ඕන. මම මේ පහල විදියට කරලා තියෙනවා. ඒ ක්‍රමය හරිද? එහෙමත් නැත්තම් ඒකෙ ගැටලු එන්න පුලුවන්ද කියන එක දැනගන්න ඕනි.
      //  ex.service.ts
      async getOrdersStorage() {
          const data = await this.storageService.get('access_token');
          const headers = new HttpHeaders({
            Authorization: `${data.token_type} ${data.access_token}`
          });
          return this.http.get(`${environment.apiUrl}/rider/pending/${data.business_id}/${data.user_id}`, { headers: headers });
        }
      
      //ex.page.ts
      this.orderService.getOrdersStorage().then(response => {
            response.subscribe(res => {
              console.log(res);
            });
          });
      
      1. මම මේක ටැබ් ලේඅවුට් එකෙන් කරගෙන යන්නේ. යූසර් කෙනෙක් ලොග් වෙලා පලවෙනි ටැබ් එකට එනකොට උඩ තියෙන ෆන්ක්ශන් එක වැඩ කරන්න ඕන. ඒ එන ඩේටා විව් එකේ ඩිස්ප්ලේ වෙන්න ඔනා. ටැබ් මාරු වෙනකොට රීෆ්‍රෙශ් වෙන්න අවශ්‍ය නෑ. මෙකට වඩාත් සුදුසු ක්‍රමය මොකක්ද?
      ngOnInit() {
           this.samplefn();
        }
      
      ionViewWillEnter() {
           this.samplefn();
        }
      
      ionViewDidEnter() {
           this.samplefn();
        }
      

      ස්තූතියි.

      1 Reply Last reply Reply Quote 0
      • Nubelle
        Nubelle Web Development last edited by

        ionic nam eting me denna tama @root @dev_lak

        1 Reply Last reply Reply Quote 1
        • root
          root Linux Help last edited by root

          මචන් මේ service එකේ තියෙන http request එක promise එකක් විදියට දාන්න

          getOrdersStorage(){
              const data = await this.storageService.get('access_token');
              const headers = new HttpHeaders({
                Authorization: `${data.token_type} ${data.access_token}`
              });
              return new Promise(resolve => {
                this.http.get(`${environment.apiUrl}/rider/pending/${data.business_id}/${data.user_id}`, { headers: headers })
                .subscribe(
                  data => {resolve(data)},
                  error=> {
                    console.log(error );
                  }
                )
              })
            }
          

          Page එක ඇතුලේ

          this.orderService.getOrdersStorage()
                .then(
                  data => this.handleSuccess(data)
                ).catch(()=>{
                  console.log("catched")
                }
              )
          
          handleSuccess(data) {
          //request success  function එක 
          }
          
          oditha 1 Reply Last reply Reply Quote 1
          • oditha
            oditha Web Development @root last edited by

            @root Thanks brother. Me widiyta karamen thiyena advantage eka mokkda? puluwan nm ekat poddak wisthara karanna puluwanda?

            root 1 Reply Last reply Reply Quote 0
            • root
              root Linux Help @oditha last edited by root

              @oditha

              Asynchronous functions ගොඩක් කරදරයි use කරන්න මොකද ඔයාට බලන් ඉන්න වෙනවා function එක ඉවරවෙනකම් අනිත් function එක run කරන්න , Promise එකක stages 3ක් තියෙනවා මේකෙදි ඔයාට errors handle කරන්න පුළුවන් ගොඩක් ලේසියෙන් ඔයා දැන් use කරන method එකට වඩා, මේ error handling එක ගොඩක්ම සමානයි synchronous try/catch එකකට මේක ගැන වැඩි විස්තර දැනගන්න Javascript Promise ගැන කියවන්න.

              ඔයාගේ මේ process එකට හරියන්නේ Promise එකක් එත් හැම එකටම Promise use කරන්නත් බැ. Async/Await use කරන්න ඕනෙම වෙලාවලුත් තියෙනවා

              oditha 1 Reply Last reply Reply Quote 1
              • oditha
                oditha Web Development @root last edited by

                @root Thanks bro :+1: :+1:

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post

                0
                Online

                3.6k
                Users

                1.3k
                Topics

                5.3k
                Posts

                • Privacy
                • Terms & Conditions
                • Donate

                © Copyrights and All right reserved Lanka Developers Community

                Powered by Axis Technologies (PVT) Ltd

                Made with in Sri Lanka

                | |