Skip to content

Instantly share code, notes, and snippets.

Created June 30, 2017 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fc9882f3e61074c98adbe4aeb585476a to your computer and use it in GitHub Desktop.
Save anonymous/fc9882f3e61074c98adbe4aeb585476a to your computer and use it in GitHub Desktop.
import { Component, OnInit } from "@angular/core";
import { Observable } from "rxjs/Observable";
import { ObservableArray } from 'data/observable-array';
import { Item } from "./item";
import { ItemService } from "./item.service";
@Component({
selector: "ns-items",
moduleId: module.id,
templateUrl: "./items.component.html",
})
export class ItemsComponent implements OnInit {
items: Item[];
categoricalSource:ObservableArray<any>;
constructor(private itemService: ItemService) { }
ngOnInit(): void {
// this.test1(); //works fine
this.test2(); //does not work
// this.test3(); //does not work
}
test1() {
this.categoricalSource = new ObservableArray([
{ Country: "Germany", Amount: 15, SecondVal: 14, ThirdVal: 24, Impact: 0, Year: 0 },
{ Country: "France", Amount: 13, SecondVal: 23, ThirdVal: 25, Impact: 0, Year: 0 },
{ Country: "Bulgaria", Amount: 24, SecondVal: 17, ThirdVal: 23, Impact: 0, Year: 0 },
{ Country: "Spain", Amount: 11, SecondVal: 19, ThirdVal: 24, Impact: 0, Year: 0 },
{ Country: "USA", Amount: 18, SecondVal: 8, ThirdVal: 21, Impact: 0, Year: 0 }
]);
}
test2() {
setTimeout(()=>{
this.categoricalSource = new ObservableArray([
{ Country: "Germany", Amount: 15, SecondVal: 14, ThirdVal: 24, Impact: 0, Year: 0 },
{ Country: "France", Amount: 13, SecondVal: 23, ThirdVal: 25, Impact: 0, Year: 0 },
{ Country: "Bulgaria", Amount: 24, SecondVal: 17, ThirdVal: 23, Impact: 0, Year: 0 },
{ Country: "Spain", Amount: 11, SecondVal: 19, ThirdVal: 24, Impact: 0, Year: 0 },
{ Country: "USA", Amount: 18, SecondVal: 8, ThirdVal: 21, Impact: 0, Year: 0 }
]);
});
}
test3(){
Observable.create((observer) => {
setTimeout(()=>{
observer.next([
{ Country: "Germany", Amount: 15, SecondVal: 14, ThirdVal: 24, Impact: 0, Year: 0 },
{ Country: "France", Amount: 13, SecondVal: 23, ThirdVal: 25, Impact: 0, Year: 0 },
{ Country: "Bulgaria", Amount: 24, SecondVal: 17, ThirdVal: 23, Impact: 0, Year: 0 },
{ Country: "Spain", Amount: 11, SecondVal: 19, ThirdVal: 24, Impact: 0, Year: 0 },
{ Country: "USA", Amount: 18, SecondVal: 8, ThirdVal: 21, Impact: 0, Year: 0 }
]);
}, 1000);
}).subscribe((res) => this.categoricalSource = res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment