Skip to content

Instantly share code, notes, and snippets.

@wshayes
Created March 23, 2017 13:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wshayes/5c8c853b66da59549a280cff045144e7 to your computer and use it in GitHub Desktop.
Save wshayes/5c8c853b66da59549a280cff045144e7 to your computer and use it in GitHub Desktop.
ViewEngineHooks Aurelia example
// Here's an example from Rob Eisenberg
// filename: resources/data/countries.js
import {viewEngineHooks} from 'aurelia-templating';
let countries = [
{ abbreviation: "AF", name: "Afghanistan" },
{ abbreviation: "AL", name: "Albania" },
{ abbreviation: "DZ", name: "Algeria" },
...
];
@viewEngineHooks()
export class CountryBinder {
beforeBind(view) {
view.overrideContext.countries = countries;
}
}
// view template filename: account.html
<template class="user-detail" bindable="controller">
<require from="resources/data/countries"></require>
...
<div class="form-group">
<label class="col-sm-2 control-label">Country</label>
<div class="col-sm-3">
<select class="form-control">
<option value="" selected="selected">(please select a country)</option>
<option repeat.for="country of countries" value.bind="country.abbreviation">${country.name}</option>
</select>
</div>
</div>
...
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment