You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{ZeroService}from'zero-angular/zero.service';import{QueryService}from'zero-angular/query.service';
...
import{Schema}from'../util/schema';// import your Schema Type
...
exportclassMessagesComponentimplementsOnInit{
...
// Inject Services via Constructorconstructor(privatezeroService: ZeroService<Schema>,privatezeroQuery: QueryService){}ngOnInit(): void{ths.fetchSync();this.fetchUsingQuerySubscription();}// Example Zero fetch for data that does not need live updatesfetchSync(){this.users=this.zeroService.getZero().query.user.materialize("forever");this.mediums=this.zeroService.getZero().query.medium.materialize("forever");this.allMessages=this.zeroService.getZero().query.message.materialize("forever");}// Subscribe to Query data enabling realtime updatesfetchUsingQuerySubscription(){// Build the Query using the ZeroServiceletquery=this.zeroService.getZero().query.message.related("medium").related("sender").orderBy("timestamp","desc").limit(20);if(this.filterUser){query=query.where("senderID",this.filterUser);}if(this.filterText){query=query.where("body","LIKE",`%${this.filterText}%`);}// Use the Query with the Query Service and Subscribethis.zeroQuery.useQuery(query).subscribe(([results,resultType])=>{console.log('Query Result:',results,resultType);});}
...
}
...