GitHub - sscholle/zero-angular
Angular bindings for Zero.
import { Zero } from '@rocicorp/zero'; import { provideZero } from 'zero-angular/zero.service'; ... import { schema } from '../util/schema';// import your schema Instance ... provideZero(new Zero({ schema, server: 'http://localhost:4848', userID: 'anon' })) ...
import { ZeroService } from 'zero-angular/zero.service'; import { QueryService } from 'zero-angular/query.service'; ... import { Schema } from '../util/schema';// import your Schema Type ... export class MessagesComponent implements OnInit { ... // Inject Services via Constructor constructor(private zeroService: ZeroService<Schema>, private zeroQuery: QueryService) {} ngOnInit(): void { ths.fetchSync(); this.fetchUsingQuerySubscription(); } // Example Zero fetch for data that does not need live updates fetchSync(){ 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 updates fetchUsingQuerySubscription(){ // Build the Query using the ZeroService let query = 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 Subscribe this.zeroQuery.useQuery(query).subscribe(([results, resultType]) => { console.log('Query Result:', results, resultType); }); } ... } ...