this.getModel.metadataLoaded()
What is the main purpose of using this metadataLoaded?
What are the advantage and disadvantage of metadataLoaded?
Metadata is the information about the oData service itself. It contains entity, entityset, association information, field labels and all the other configuration it needs. The oData model uses it, smart controls are built on top of it. You'll find calls to fetch this at the start of every application (look for $metadata in the console of the browser). Before this is loaded, you can't use the service. In most cases this will be ready before your view is displayed.
metadataLoaded() returns a promise you can use to do things if you want to make certain that the service is ready, like:
this.getModel().metadataLoaded().then(_ => {
//use the service here to load some data
this.getView().bindElement({
path: `/PathToMyEntitySet('Key')`,
events: {
dataRequested: _ => this.getView().setBusy(true),
dataReceived: data => console.log(data),
change: _ => this.getView().setBusy(false)
}
});
});