Reputation: 4906
I have a custom element called contact
, the purpose of this element is that it serves as a chat messenger contact. I have an array in the parent called contacts
. It looks like this:
contacts = [
{
firstName: 'First name',
lastName: 'Surname'
}
];
The parent HTML is called messages
and what I want to happen is that in a repeat.for
statement the data from this array gets bound to the custom element. I have already tried this
<contact repeat.for="contact of contacts"></contact>
But how do I bind contact
in the repeat.for to the custom element?
Upvotes: 2
Views: 100
Reputation: 1196
If you have contact.js
import {bindable} from 'aurelia-framework';
export class Contact {
@bindable data;
}
in contact.html
<template>
${data.firstName} ${data.lastName}
</template>
in messages.js
export class Messages {
contacts = [
{
firstName: 'First name',
lastName: 'Surname'
}
];
}
in messages.html
<template>
<require from="./contact"></require>
<contact repeat.for="contact of contacts" data.bind="contact"></contact>
</template>
Upvotes: 4