I have a single HTML element :
<ul id="animals"></ul>
And this code which observe an array and append its element as HTML elements :
const zooAnimals = ['anteater', 'bear', 'cheetah', 'donkey'];
const observable = Rx.Observable.from(zooAnimals);
const subscriber = observable
.subscribe(
onNext,
function onError(err) {
console.log('Error: ' + err);
},
function onCompleted() {
console.log('no more animals!');
}
);
function onNext(animal) {
const list = document.querySelector('#animals');
console.log('list', list)
const li = document.createElement('li');
li.innerHTML = animal;
list.appendChild(li);
}
So now the #animals
element is filled with 4 ULs
.
But Now I want to add another element via setTimeout
So I add :
setTimeout(function (){
zooAnimals.push('dddddd');
},4000);
But nothing happens.
Question
What am I missing here and how can I mek this code work if some other soure appends items to the array.
plunker :