دنبال کننده ها

۱۳۹۶ مرداد ۱۰, سه‌شنبه

angularjs - Angular update class when data changes

[ad_1]



So, I'm using firebase to store my data, so we have a realtime database;



And I'm setting a class like this:




[ngClass]="isReserved(slot) ? 'reserved-slot': 'free-slot'"




This checks an array if it exists, that array is populated in construct, and uses subscribe.



The data is updating live, if I click on an item, but if I got into firebase and delete a slot manually the class doesn't change.




So how can I make the class change in realtime too, when change is
detected?




isReserved(dateTimeBusinessID) 
if(typeof this.reservedSlots[dateTimeBusinessID] === "undefined" ) return false;
return true;



This is how I populate the array on construct



private getReservedSlots() 

this.firebase.database.list('/reservations', query: orderByChild: 'DateBusinessID', equalTo: this.formattedDateBusinessID )
.subscribe((data) =>
if (data.length > 0)
for (var i = 0; i < data.length; i++)
var keyArray = data[i].time;
this.reservedSlots[keyArray] = 'class': 'false'

console.log('changed detected');

);



The thing is I get "changed detected" when I manually delete data from firebase, so I guess I'm doing something wrong in the html;




[ad_2]

لینک منبع