Skip to content

Instantly share code, notes, and snippets.

@mattduffield
Last active October 7, 2016 17:48
Show Gist options
  • Select an option

  • Save mattduffield/65ac271f0d578ad4c6f4107247b6e455 to your computer and use it in GitHub Desktop.

Select an option

Save mattduffield/65ac271f0d578ad4c6f4107247b6e455 to your computer and use it in GitHub Desktop.
Aurelia Gist - getViewStrategy - ViewService (simple)
<template>
<h1>${title}</h1>
<compose view-model="dynamic"></compose>
</template>
export class App {
title = 'Dynamic Screens'
}
import {InlineViewStrategy} from 'aurelia-templating'; import {ViewService} from './view-service'; export class Dynamic { static inject = [ViewService]; constructor(viewService) { this.viewService = viewService; } getViewStrategy() { let template = this.viewService.getView('simple'); let vs = new InlineViewStrategy(template.view, this); return vs; } }
<!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>
/** * Provides view markup. * * @class ViewService */ export class ViewService { constructor() { this.views = []; this.initViews(); } getView(name) { return this.views.find((v) => { return v.name === name; }) } initViews() { this.views = [ { name: 'simple', view: ` <template> <h2>Inside simple dynamic template!</h2> </template> ` } ]; } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment