Skip to content

Instantly share code, notes, and snippets.

@RichTeaTime
Last active October 20, 2016 12:06
Show Gist options
  • Save RichTeaTime/f786c93f86ba8b22a323bfe50e176210 to your computer and use it in GitHub Desktop.
Save RichTeaTime/f786c93f86ba8b22a323bfe50e176210 to your computer and use it in GitHub Desktop.
Aurelia Gist - using @Inject(NewInstance) does not work correctly with container.registerInstance
<template>
<require from="component"></require>
<div>expected: <span innerHTML.bind="mocktext"></span></div>
<div>actual: <component></component></div>
</template>
import {Container} from 'aurelia-framework'
import {BaseClass} from 'base-class'
import {MockClass} from 'mock-class'
export class App {
static inject = [Container];
mocktext = "";
constructor(container:Container)
{
this.mocktext = new MockClass().text;
container.registerHandler(BaseClass, c => new MockClass());
}
}
export class BaseClass
{
text = "<font color='red'>base class</red>";
}
<template>
<span innerHTML.bind="message"></span>
</template>
import {BaseClass} from 'base-class'
import {NewInstance} from 'aurelia-framework'
export class Component
{
messsage = "";
static inject = [NewInstance.of(BaseClass)];
constructor(baseInstance)
{
this.message = baseInstance.text;
}
}
<!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>
import {BaseClass} from 'base-class';
export class MockClass extends BaseClass
{
constructor() {
super();
this.text = "<font color='green'>mock class</font>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment