Skip to content

Instantly share code, notes, and snippets.

@3cp
Last active February 23, 2018 00:15
Show Gist options
  • Select an option

  • Save 3cp/2e568eb41da7d187e6214ad26b842619 to your computer and use it in GitHub Desktop.

Select an option

Save 3cp/2e568eb41da7d187e6214ad26b842619 to your computer and use it in GitHub Desktop.
as-element
<template>
<require from="./my-comp"></require>
<h4 as-element="my-comp"></h4>
<h4 as-element="compose" view-model="./my-comp"></h4>
</template>
export class App {
}
<!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>
<p>my comp</p>
</template>
import {inject} from 'aurelia-framework';
@inject(Element)
export class MyComp {
constructor(element) {
if (element.tagName === 'MY-COMP') {
throw new Error("cannot use <my-comp>. use <other-tag as-element=\"my-comp\">.");
}
if (element.tagName === 'COMPOSE') {
throw new Error("cannot use <compose view-model=\"my-comp\">. use <other-tag as-element=\"compose\" view-model=\"my-comp\">.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment