0

I'm trying to get a number from splitting a URL so I could use it in my function, for some reason I keep getting "this.activeId" is undefined. Why is that? I tried looking at other resources and I still dont understand why.

activeId = 0;

ngOnInit() {

    this.route.params.subscribe(response => {
        let path = window.location.pathname.split(";")[0].split("/").pop();
        this.activeId = parseInt(path);
        console.Log(this.activeId);
      }
    }

    next() {
      const next = this.activeId + 1 >= 9 ? 1 : this.activeId + 1;
      this.router.navigateByUrl('/image/' + `${next};id=${this.domain.id};category=${this.domain.category};`);
    }
JZG
  • 45
  • 1
  • 9
  • I looked it at this same question before I wrote this. I'm still confused – JZG Apr 07 '18 at 19:39
  • Then please elaborate on what you don't understand about the other answers. It'll be hard to explain general async behavior any better than the existing answers. – baao Apr 07 '18 at 20:34
  • Can you provide an example or something. Maybe hearing it from another perspective would help. I just don't understand the whole concept. Why wouldn't I be able to give the "path" to the activeId and then call it in a function? So confused. – JZG Apr 07 '18 at 20:51
  • From the code sample you provided I see no way in which activeId could be undefined. – Adrian Fâciu Apr 08 '18 at 07:44
  • @AdrianFâciu Same that's why I'm confused. I even looked at the resources they provided and it does help me to understand. – JZG Apr 08 '18 at 22:17

0 Answers0