интерфейс карты:
Код: Выделить всё
export interface iCard {
idx: number
name: string
value: string
site: string
}
Код: Выделить всё
@customElement('sx-card')
export class AppCard extends LitElement implements iCard {
@property({type: Number}) idx = 1;
@property({type: String}) name = '';
@property({type: String}) value = '';
@property({type: String}) site = '';
render() {
return html`${this.name}`;
}
}
Код: Выделить всё
@customElement('sx-cards')
export class AppCards extends LitElement {
connectedCallback(): void {
super.connectedCallback();
this.loadCards();
}
async loadCards(): void {
let ajaxService = new AjaxService();
let cards = await ajaxService.getCards();
cards.forEach((card: iCard) => {
let elCard: AppCard = document.createElement('sx-card') as AppCard;
// This is where I need to pass the values from the "card" response to the "elCard" component
this.appendChild(elCard);
});
}
}
< em> и если у вас есть какие -либо предложения по улучшению кода, я буду признателен, я изучаю TS.
Подробнее здесь: https://stackoverflow.com/questions/794 ... -interface
Мобильная версия