I'm creating an observable using an array. When I call subscribe method its length becomes doubles.
ie. if array has 3 items after subscribe it becomes 6 by duplicating same items.
I'm also using async pipe to list down items in html.
Please check the plunker example
@Component({
selector: 'my-app',
template: `
<div>
<ul>
<li *ngFor="let data of obs|async">
{{data.name}}
</li>
</ul>
</div>
`
})
export class App implements OnInit{
obs: Observable<any>;
arr = [{
name: 'name1',
age: 26
}, {
name: 'name2',
age: 27
}, {
name: 'name3',
age: 28
}];
constructor() {
}
ngOnInit() {
this.obs = Observable.from(this.arr).toArray()
this.obs.subscribe(res => {
console.log(res)
})
}
}
Output :
- name1
- name2
- name3
- name1
- name2
- name3