Created
August 28, 2016 23:32
-
-
Save martonsagi/4e2ec80c1010c638e908589ce3fc5067 to your computer and use it in GitHub Desktop.
Inline template in custom aurelia component
This file contains 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> | |
<require from="./inline"></require> | |
<div class="container-fluid"> | |
<h4 class="page-header">Inline template in custom component</h4> | |
<div class="form-group"> | |
<label>Template:</label> | |
<input class="form-control" type="text" value.bind="customTemplate" /> | |
</div> | |
<div class="form-group"> | |
<label>Display Value:</label> | |
<input class="form-control" type="text" value.bind="customValue" /> | |
</div> | |
<div class="panel panel-primary"> | |
<div class="panel-heading">Rendered view:</div> | |
<div class="panel-body"> | |
<inline template.bind="customTemplate" display-value.bind="customValue"></inline> | |
</div> | |
</div> | |
</div> | |
</template> |
This file contains 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 { | |
customTemplate = '<i class="fa fa-3x fa-${displayValue}"></i>'; | |
customValue = 'stack-overflow'; | |
} |
This file contains 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"> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous"> | |
</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 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> | |
<compose view.bind="viewStrategy"></compose> | |
</template> |
This file contains 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 { bindable, bindingMode, InlineViewStrategy } from 'aurelia-framework'; | |
export class Inline { | |
viewStrategy; | |
@bindable({ defaultBindingMode: bindingMode.oneWay }) | |
template; | |
@bindable({ defaultBindingMode: bindingMode.oneWay }) | |
displayValue; | |
attached() { | |
this.render(); | |
} | |
templateChanged() { | |
this.render(); | |
} | |
render() { | |
this.viewStrategy = new InlineViewStrategy(`<template>${this.template}</template>`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment