Skip to content

Instantly share code, notes, and snippets.

@arjanvanderleden
Forked from jdanyow/app.html
Created March 16, 2016 14:22
Show Gist options
  • Save arjanvanderleden/0efbaea028450163d98e to your computer and use it in GitHub Desktop.
Save arjanvanderleden/0efbaea028450163d98e to your computer and use it in GitHub Desktop.
Aurelia repeat.for binding on a template
<template>
<require from="./menu-item"></require>
<div>${message}</div>
<div>menu Items : ${menuItems.length}</div>
<ul>
<li repeat.for="item of menuItems">${item.label}</li>
</ul>
<ul>
<menu-item repeat.for="item of menuItems" containerless ></menu-Item>
</ul>
<ul>
<menu-item repeat.for="item of menuItems" containerless current.bind="item"></menu-Item>
</ul>
</template>
import {MenuItem} from 'menu-item'
export class App {
message = 'hello world';
menuItems = [];
constructor(){
this.menuItems.push(new MenuItem("Home"));
this.menuItems.push(new MenuItem("About"));
this.menuItems.push(new MenuItem("Contact"));
console.log('app constructor');
}
attached(){
console.log('app = attached');
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
<template>
<li>${label} or ${current.label}</li>
</template>
import {bindable, customElement} from 'aurelia-framework'
@customElement('menu-item')
export class MenuItem{
label = "default label";
@bindable current;
constructor(label){
this.label = label;
}
attached(){
console.log("MenuItem = attached");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment