aurelia

Binding a select to an array of objects in Aurelia and matching on ID

给你一囗甜甜゛ 提交于 2020-01-01 04:41:08
问题 So, I have a list of all users, which populates the options of a select. <option repeat.for="user of userService.users"> ${user.firstName} ${user.lastName} </option> And I have an incoming group record which has a list of users attached to it. I follow the cheat sheat instructions and bind it to a single index of the model. <select value.bind="group.users[0]"> <option repeat.for="user of userService.users" model.bind="user"> ${user.firstName} ${user.lastName} </option> </select> So, the

How to tear down an enhanced fragment

爱⌒轻易说出口 提交于 2020-01-01 03:47:48
问题 I am working on an existing SPA where we replace components with Aurelia components step by step. We use the enhance API of the TemplatingEngine . That works pretty well but we also need to tear down those enhanced fragments (remove event listeners, ...) when moving to another part of the application (no page reload). My idea is to keep the aurelia instance in the page and reuse it. Currently I enhance fragments like this: function enhanceFragment(targetElement) { function proceed() { let

Aurelia dynamic binding

眉间皱痕 提交于 2019-12-31 02:30:07
问题 I've created a custom element that generates tabular data. For good reasons, this generates the actual HTML and inserts into the DOM without using a template. I need to attach click observers to specific elements to I can run a function in the custom element in response to a click. If using a template, I'd use click.delegate, but I can't use that with generated HTML. How do you attach an event handler with Aurelia other than by using jQuery? 回答1: I know this answer is late, but in case this

Aurelia: configure fetch client

戏子无情 提交于 2019-12-30 10:36:22
问题 I use Aurelia's fetch client to communicate with my server. In every viewModel using the fetch client I have to configure it the client to use an interceptor to send a custom header(a token). Is there a way to configure the fetch client once somewhere instead of rewriting the interceptor code in each viewModel. 回答1: You could put the configuration in the main.js file. Like this: ... aurelia.use .standardConfiguration() .developmentLogging(); let container = aurelia.container; let http = new

Access a DOM element in Aurelia

主宰稳场 提交于 2019-12-30 07:52:01
问题 How would you go about accessing a DOM element in Aurelia? This is a broad and general question, but I have a feeling there are one or two preferred ways to do this. I have two current cases in Aurelia now: In the template I have a form. I want to access the form element in the view-model, on VM canDeactivate(), to interrupt a user navigating away from a half filled out form. So the scope in which I'm trying to access the element can be considered local. In another view-model I want to hide

How do you use ViewCompiler to manually compile part of the DOM?

ぃ、小莉子 提交于 2019-12-30 07:24:29
问题 Say I have a simple view model ( widget.js ): import {Behavior} from 'aurelia-framework'; export class Widget { static metadata() { return Behavior.customElement('widget') } constructor() { this.title= "AwesomeWidget"; } } With the following view: ( widget.html ): <template> <div>${title}</div> </template> Now say I inject some markup like this into the DOM: var markup = `<div><widget></widget></div>`; var $markup = $(markup); var $placeholder = $("#placeholder"); $placeholder.append($markup)

How to add Tether in Aurelia-CLI to use with Bootstrap 4

♀尐吖头ヾ 提交于 2019-12-30 06:38:13
问题 I am trying to add Bootstrap 4 to Aurelia . I can only get the CSS to work but the bootstrap.js requires Tether and I can't get it included, since I keep getting this error in the console: Bootstrap tooltips require Tether I tried something along this "jquery", "Tether", { "name": "tether", "path": "../node_modules/tether/dist", "main": "js/tether.min", "exports": "Tether", "resources": [ "css/tether.css" ] }, { "name": "bootstrap", "path": "../node_modules/bootstrap/dist", "main": "js

Reload current page in Aurelia

为君一笑 提交于 2019-12-30 05:54:20
问题 I have an Aurelia application where the user can select the company they're currently "working on". Every page in the app is dependent on the currently selected company, and the user can select a new company from a drop-down menu. The drop-down is a component sitting on the nav-bar. What I'd like is to have that component reload the current page on the change.delegate handler without restarting the app. So setting window.location.href is out of the question. Is there a way to force the

How to set default activationStrategy in aurelia

时光总嘲笑我的痴心妄想 提交于 2019-12-29 07:37:07
问题 Aurelia normally ignores any changes in the querystring. It is possible to set the activationStrategy to invoke-lifecycle in the VM so it will re-run the all the life cycles in the VM when the querystring changes. To prevent littering my code (placing it in every VM) i want to set the default activationStrategy to invoke-lifecycle . In the interface it's explained that it is possible, but how to set it? https://github.com/aurelia/router/blob/master/src/interfaces.js 回答1: On the ViewModel (I

Aurelia load routes dynamically / from fetch

梦想的初衷 提交于 2019-12-29 07:18:49
问题 I want to load menu options dynamically. so I'm wondering the best approach I am able to use the code below to add routes after the page is loaded. This works for normal navigation, but does not work during a refresh. Can configure router return a promise / how do I load menu items into the route? @inject(HttpClient) export class DocumentMenu { router: Router; documents : IDocument[]; heading = 'Document Router'; constructor(public http: HttpClient) {} activate(): void { this.http.fetch('http