-
-
Save ypcode/f24c1036a2feb00364248c3416aa5464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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