Skip to content

Instantly share code, notes, and snippets.

@ypcode
Last active January 25, 2019 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/f24c1036a2feb00364248c3416aa5464 to your computer and use it in GitHub Desktop.
Save ypcode/f24c1036a2feb00364248c3416aa5464 to your computer and use it in GitHub Desktop.
// ...
private listDataService: IListService;
public onInit(): Promise<void> {
return ComponentServices.init(this.context,
this.properties, (startup, ctx, props) => {
// // Register a new scoped instance of the service
startup.registerScopedService(ListService.serviceKey, ListService);
// Configure the service instance with the component specific properties
startup.configureService(ListService.serviceKey, service => {
service.configure(ctx.pageContext.web.absoluteUrl, props.listId);
});
// Must return a resolved promise
// (useless here but needed in case on async needs in the config process)
return Promise.resolve();
}).then(serviceScope => {
// Consume the list service
// Instead of keeping a service reference assigned here,
// one can use ComponentServices.serviceScope.consume(ListService.serviceKey);
this.listDataService = serviceScope.consume(ListService.serviceKey);
// ...
}).catch(error => {
console.log('Error on init: ', error);
});
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment