Last active
October 7, 2016 17:48
-
-
Save mattduffield/65ac271f0d578ad4c6f4107247b6e455 to your computer and use it in GitHub Desktop.
Aurelia Gist - getViewStrategy - ViewService (simple)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <h1>${title}</h1> | |
| <compose view-model="dynamic"></compose> | |
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class App { | |
| title = 'Dynamic Screens' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** * 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