Skip to content

Instantly share code, notes, and snippets.

@Danetag
Created May 20, 2020 02:29
Show Gist options
  • Save Danetag/cb7ed4b471d413aa800ae146ec1a08cb to your computer and use it in GitHub Desktop.
Save Danetag/cb7ed4b471d413aa800ae146ec1a08cb to your computer and use it in GitHub Desktop.
/* In a web component */
// Private function to get the data from the "<script>" element
selectData = () => {
const options = this.slotContainerRef.querySelector('script');
const optionsJSON = !!options && JSON.parse(options.innerHTML);
if (optionsJSON) {
return optionsJSON;
}
return null;
}
// Also provide a Method to be able to inject the data via JS
@Method async setData(data) {
this.data = data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment