Hi Sander,

There is something very misterious here and I'll try to explain:

I have the following service:

@Injectable()
export class BundleService {
private url = environment.bundleServiceCallUrl;
constructor(private http: HttpClient) {
}

public getBundles(): Observable<Array<Bundle>> {
const params = new HttpParams().set("start", "0");
return this.http.get<Array<Bundle>>(this.url, { params });
}
}

It returns an array of objects of class Bundle. Its consumer looks as 
follows:

constructor(private bundleService: BundleService) { }
...
public ngOnInit() {
...
this.bundleService.getBundles().subscribe((bundlesArray: Array<Bundle>) => {
this.pushBundles(bundlesArray)},
(err: HttpErrorResponse) => {
if (err.error instanceof Error) {
console.log("### Client-side error occured.");
} else {
console.log("### Server-side error occured.");
}
});
............
}

The service is called normally, it replies with the following array of 
Bundle objects:


   1. 0: {codePk: "DynamicBundle", label: "DynamicBundle", isActive: "1"}
   2. 1:{codePk: "IsoLanguage", label: "Iso Languages", isActive: "1"}
   3. 2:{codePk: "Test_Bundle", label: "Test_Bundle", isActive: "1"}
   4. 3:{codePk: "TranscludeBundles", label: "Transclude bundles for tests"
   , isActive: "1"}
   5. 4:{codePk: "TranscludedBundle1", label: "Transcluded bundle 1", 
   isActive: "1"}
   6. 5:{codePk: "TranscludedBundle2", label: "Transcluded bundle 2", 
   isActive: "1"}
   7. 6:{codePk: "TranscludedBundle1a", label: "Transcluded bundle 1a", 
   isActive: "1"}
   8. 
   9. This array of bundles is passed to the pushBundles method, as follows:
   10. 
   11. private pushBundles(bundlesArray: Array<Bundle>) {
   for (let bundle of bundlesArray)
   this.bundles.push({label: bundle.label, value: {codePk: bundle.codePk, 
   label: bundle.label, isActive: bundle.isActive}});
   }
   1. 
      2. And here the for ;;; of loop behaves like the input parameter is 
      not an Array as it display "object false" for typeof bundlesArray, 
      Array.isArray(bundlesArray).
      3. 
      4. In order to get things running I had to replace in the code above:
      5. 
      6. this.pushBundles(bundlesArray)
      7. 
      8. by
      9. 
      10. this.pushBundles(bundlesArray["bundles"])
      11. 
      
I don't know what "bundles" is and where does it comes but this way it 
works. So, it appears that bundlesArray id not an array of Bundle but 
something like an array having one element which is my array of Bundle. If 
you have some ideas to shade some light here, I would be very obligated to 
you.

Many thanks in advance,

Nicolas


Le mardi 22 août 2017 14:41:22 UTC+2, Sander Elias a écrit :
>
> Hi Nicolas,
>
> You have an object that looks like an array. I'm not enierly sure, but I 
> suspect i fyou do something like this: 
> bundles = Array.from(bundles)
>
> You might need to set the length to the proper number before this works.
>
> Regards
> Sander
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to