Skip to content

Instantly share code, notes, and snippets.

@charlespockert
Last active May 15, 2016 10:48
Show Gist options
  • Save charlespockert/11d19b73981c7a890768fa6447e039d6 to your computer and use it in GitHub Desktop.
Save charlespockert/11d19b73981c7a890768fa6447e039d6 to your computer and use it in GitHub Desktop.
Aurelia Dependency-Injection Example
<template>
<h1>${b.message}</h1>
</template>
import {B} from './b';
import {inject} from 'aurelia-dependency-injection';
@inject(B)
export class App {
constructor(b) {
this.b = b;
}
}
import {C} from './c';
import {inject} from 'aurelia-framework';
@inject(C)
export class B {
constructor(c) {
this.c = c;
this.message = "The date is :" + this.c.getDate();
}
}
export class C {
constructor(date) {
this.date = date || new Date();
}
getDate() {
return this.date;
}
}
<!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://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment