Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Zurie
    @zurie
    take the string off and then see wht res gives you
    Ghost
    @ghost~58a45227d73408ce4f4a8666
      public translateValue(key: string): string {
        let result: string;
        this.translate.get(key).subscribe((res: string) => {
          result = res;
        });
        return result;
      }
    Zurie
    @zurie
    is this a pipe
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    It shows that result is not defined
    Zurie
    @zurie
    or is this a function
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    it is a function
    Zurie
    @zurie
    i did this subscribe
     updateUser(value): void {
        this.loading.present();
        this.fab.updateUser(this.navParams.get('myUser').CustomerID, value)
          .subscribe(
          res => {
            console.log(res);
            this.loadUser('email', this.fab.fab_user);
          },
          err => {
            // Log errors if any
            console.log(err);
          });
      }
    Owen Melbourne
    @OwenMelbz
    thats not how it works
    subscribe is like then - its an async function
    you cant return a value from it
    you'd have to do something like
    this.translateValue('something').then(result => console.log(result));
    or similar to @zurie
    but yeah you cant return a value from a async function such as subscribe
    you CAN assign in the callbacks (like zurie)
    Zurie
    @zurie
    loadHistory(id) {
    
        this.fab.getHistory(id)
          .subscribe(
            res => {
              // debugger;
    
              this.profile.history = res ,
                this.loading.dismiss(),
                this.queried = true;
            },
            err => {
              // Log errors if any
              console.log(err);
            });
      }
    <div class="invoice-wrapper"
             *ngFor="let invoice of this.profile.history |  orderBy : '-' | search: myProgress; let i=index"
             [ngClass]="{active: isLevel1Shown('idx'+i)}">
    makes it really hard to understand out of context
    but basically its not like json of the past where you just get data and return key values
    its like now you are subscribing to a stream
    and the stream has your data but also has all this other RXjS stuff
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    @zurie Does this code for me or not?
    Zurie
    @zurie
    no
    nothing really codes for you
    Owen Melbourne
    @OwenMelbz
    @Teodor_ASA_twitter maybe do some reading on how subscriptions and promises work and it will make it more clear
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    @OwenMelbz maybe that apply to all people here. Lets close this chat?
    Zurie
    @zurie
    if you want some good examples you can goto google and type this site:stackblitz.com angular observable
    search the stackblitz.com site and whatever you want and you can find lots of examples from people sorta like jsfiddle or codepen that have angular observables and subscribes etc etc. then when you see a few its easier to get
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    there is millions other sites with examples
    please if you don't know what is the answer (as me) don't give answer from sort "google it"
    Owen Melbourne
    @OwenMelbz
    the chat isnt to teach people how javascript principles work - the chat is for general q/a about ionic. if you need help with specific piece of code of functionality then websites like stackoverflow exist to get solutions to actual problems
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    I have asked for a help. My question wasn't "Please give me link for subscription examples"
    Owen Melbourne
    @OwenMelbz
    and the answer was
    subscriptions cannot return values
    Zurie
    @zurie
    also stackblitz.com lets you make an example and share it, so if you want maximum help, you can make a example with stackblitz, and then say the question, and then link it and then its easier to see it in context
    Owen Melbourne
    @OwenMelbz
    they return promises
    Zurie
    @zurie
    no they dont
    promises are 1 time
    Owen Melbourne
    @OwenMelbz
    sure, but in this example
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    really? so why in component I can set a string to return value of subscription
    Owen Melbourne
    @OwenMelbz
    point is if he returns a subscription - he's not gonna get the value from it
    Zurie
    @zurie
    right
    strings are not subscriptions
    or integers
    so you can't get "hello world" from it
    or 2.25
    Ghost
    @ghost~58a45227d73408ce4f4a8666
    yes I can