Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49355

Accessing variable from other .ts files

$
0
0

@king-ds wrote:

Hi there,

I just want to know on how to access the variable from the other .ts files?

Like for example,

Here is my api.service.ts:

This is the variable I want to access

public success : boolean = false;

Function for updating the success variable

 login_clinician(data){
   return new Promise(resolve=> {
     this.http_client.post(this.url+'authenticate/clinicians', JSON.stringify(data), http_options)
     .subscribe(res => {
       resolve(res);
       this.success = true;
     },
     (error) => {
       reject(error);
       console.log(error);
       this.success = false;
     });
   });
 }

Here is the code for another .ts file named login.page.ts. What I want to do is to access the success variable from api.service.ts here:

  login_clinician(){
    this.submit_attempt = true;
    this.login_loader = true;

    let login_data = {
      'student_number' : this.login_clinician_form.value.student_number,
      'password' : this.login_clinician_form.value.password,
    }

    this.api_service.login_clinician(login_data)
    console.log(this.api_service.success);
  }

But when I’m trying to print its value, its undefined.

This is my goal, in login.page.ts I want to access the success variable from api.service.ts. Anyone know how to do it? Thanks!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49355

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>