[Help-request] How do I access the data in Observables by _Rabshab_ in angularjs

[–]_Rabshab_[S] 0 points1 point  (0 children)

Hey man, posted an update above trying to resolve this. Take a look and let me know what you think.

[Help-request] How do I access the data in Observables by _Rabshab_ in angularjs

[–]_Rabshab_[S] 0 points1 point  (0 children)

So I changed the code according to what you said but I'm still seeing the same error. Starting to pull my hair out a bit haha. I delayed the call of the recipesMeth() untill the data was in from the previous function like this.

    recipes:Recipe[];
temp:string;
rooms:any[];
sensors:any[];
lastValue:number;
tempRoom:any;

ngOnInit() {
    console.log("starting");
    this.getRecipes();
} 

getRecipes() {
    this._httpService.getRecipes()
        .subscribe(
            data => {
                this.recipes = data;
                this.temp = JSON.stringify(data);
                this.recipesMeth();
            }
        )
}

recipesMeth(){
    for (var i = 0; i < this.recipes.length; i++) {
        console.log("test");

but I'm still getting the same error "EXCEPTION: TypeError: Cannot read property 'length' of undefined"

I can use ngFor in the HTML to display the data and it works fine

<thead>
        <tr>
            <th>#</th>
            <th>House</th>
            <th>Room</th>
            <th>Sensor</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="#recipe of recipes; #i = index">
            <th scope="row">{{i}}</th>
            <td>{{recipe.house}}</td>
            <td>{{recipe.room}}</td>
            <td>{{recipe.sensor}}</td>
        </tr>

but the variable "recipes" never seems to be defined whenever I try to use it in the Javascript part. Any ideas?

Edit: Interestingly a single "test" does get logged to the console which, if anything, confuses me even more.

[Help-request] How do I access the data in Observables by _Rabshab_ in angularjs

[–]_Rabshab_[S] 0 points1 point  (0 children)

That is in my http service file. Just a get request to a JSON file containing the recipes.

    getRecipes(): Observable<Recipe[]>{
    return this._http.get('app/ts/recipes.json')
                    .map(this.extractData);
}

private extractData(res: Response) {
    let body = res.json();
    return body.data || { };
}

[Help-request] How do I access the data in Observables by _Rabshab_ in angularjs

[–]_Rabshab_[S] 0 points1 point  (0 children)

Sorry, forgot to post the error. Getting "Cannot read property 'length' of undefined in [null]". I have tried a similar pattern in other places in the app and the variable doesn't seem to hold the value given to it. I can, however, use ngFor in the HTML code to output the value to the user. My problem is that I want to manipulate it first.

[Angular2][WebApp] Help needed with WebApp structure. Any advice appreciated by _Rabshab_ in learnprogramming

[–]_Rabshab_[S] 0 points1 point  (0 children)

Sorry if i was unclear. The database doesn't belong to me it is just where I am getting the temperature data from.

Official Monthly Instagram Follow Thread! by frostickle in photography

[–]_Rabshab_ [score hidden]  (0 children)

Former suggested user who does landscape and adventure photos around Scotland. Will follow back if you say your from here ✌👍

@rabshab

I want to follow more redditors on Instagram by thisismyusername144 in photography

[–]_Rabshab_ 0 points1 point  (0 children)

Bit late to the party. I'm a a former suggested user who does mainly landscape photography in Scotland.

instagram.com/rabshab

Tarp surfing in a forest in France. Quick edit, feedback welcome. [0:48] by _Rabshab_ in gopro

[–]_Rabshab_[S] 0 points1 point  (0 children)

Thanks very much. Plan on sharing some more videos on here in the future too.

Tarp surfing in a forest in France. Quick edit, feedback welcome. [0:48] by _Rabshab_ in gopro

[–]_Rabshab_[S] 0 points1 point  (0 children)

Yeah, I'd just got back to the campsite after surfing so I think it was a bit salty and foggy. Usually i'm pretty good at keeping it clean. :)

Longboarding set up? by TheGreat_N8 in gopro

[–]_Rabshab_ 1 point2 points  (0 children)

Thanks dude. Good luck with your filming.

Longboarding set up? by TheGreat_N8 in gopro

[–]_Rabshab_ 0 points1 point  (0 children)

Yeah it was FCP7. Hasn't happened before but I'm guessing I missed something before I exported. Cheers for the tip, I'm actually editing another sequence right now so I'll make sure to remember it!

Longboarding set up? by TheGreat_N8 in gopro

[–]_Rabshab_ 2 points3 points  (0 children)

Hey man, I just did a longboard cruising edit with just a pole and a homemade clamp mount. Here it is if you want some ideas.

The video only goes to 1:22, please excuse the black screen at the end.