Framework: Allow import of exported module items into aurelia template, to allow access to static methods, static variables, enums, type definitions, etc.

Created on 22 Mar 2017  路  3Comments  路  Source: aurelia/framework

I'm submitting a feature request

Something like

equivalent of

import {App, SomeEnum} from "../app";

<require def="App, SomeEnum" from="../app"/>

<some-element
    some-enum-value.bind="SomeEnum.EnumValue1"
    >
    ${App.messagesById[messageId].messageToShow}
</some-element>

etc.

  • What is the motivation / use case for changing the behavior?

Aurelia seems incomplete unless this is provided.

documentation enhancement help wanted question

Most helpful comment

Here's an example:

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.html

<template class="user-detail" bindable="controller"> 
  <require from="resources/data/countries"></require>

  <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>
</template>

All 3 comments

It can be done already, though not automatically. You would use view engine hooks to declare what should be attached to the override binding context. Then when you imported that module it would make available the items you wanted.

Here's an example:

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.html

<template class="user-detail" bindable="controller"> 
  <require from="resources/data/countries"></require>

  <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>
</template>
async triageQuestion(id) =>{
 respondSameDay()
 let response = await getResponseFromOP( { timeout : Year} )
 if(!response) {
    closeQuestion(id,randomReason())
 }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

FunkMonkey33 picture FunkMonkey33  路  5Comments

ConductedClever picture ConductedClever  路  5Comments

bsrdjan picture bsrdjan  路  5Comments

ghost picture ghost  路  4Comments

piet-v picture piet-v  路  3Comments