aurelia-binding

Array subscription in Aurelia

那年仲夏 提交于 2019-11-28 21:31:45
问题 Let's say I have an array of elements and in addition to displaying the list in my app, I want to sync the list to the server with HttpClient . How can I observe changes to the array? I tried: @inject(ObserverLocator) export class ViewModel { constructor(obsLoc) { this.list = []; obsLoc.getObserver(this, 'list'); .subscribe(li => console.log(li)); } } But I got neither error nor log message. 回答1: getObserver returns a property observer which will notify you when the ViewModel class instance's

Observe property on an array of objects for any changes

試著忘記壹切 提交于 2019-11-28 21:21:55
问题 I am using Aurelia and I have an array of items bound to a grid and they have a selected property on them. I want to bind a button to be enabled when any one of the items is true. I can do a brute force approach where I have a getter that is filtering the list and returning the selected items, but that means that I would be doing dirty checking constantly in the app and I don't want to do that. I am hoping for a more efficient approach. Any ideas? 回答1: Few things you could do- assuming I have

@bindable changeHandler fires before bindings are done updating

╄→尐↘猪︶ㄣ 提交于 2019-11-28 14:00:24
The Code: App.js export class App { constructor() { this.widgets = [{ name: 'zero'}, {name: 'one'}, {name:'two'}]; this.shipment = { widget: this.widgets[1] }; } } App.html <template> <require from="./widget-picker"></require> <require from="./some-other-component"></require> <widget-picker widget.bind="shipment.widget" widgets.bind="widgets"></widget-picker> <some-other-component widget.bind="shipment.widget"/> </template> widget-picker.js import {bindable, bindingMode} from 'aurelia-framework'; export class WidgetPicker { @bindable({ defaultBindingMode: bindingMode.twoWay, changeHandler:

How to add bindable attributes or any other decorators to a typescript class via decorator?

我只是一个虾纸丫 提交于 2019-11-28 06:37:36
问题 I want to extend the behavior and data of a class using decorators instead of inheritance. I also want to apply decorators as well to the newly created properties or methods. Is there an example of how to do this? Is this even possible? Imagine a set of classes where some of these classes share a bindable property named span . Also let there be a computed property named leftMargin dependent on the span property. The desired way to implement this would be to decorate the class with a decorator

Aurelia: During a Router's Pipeline Step, how do I bind a variable to that router?

社会主义新天地 提交于 2019-11-28 00:58:10
问题 I'd like to pass the user, found during the AuthorizeStep to either the App class and then to the home module . Here's what I have: export class App { configureRouter(config, router) { config.addPipelineStep('authorize', AuthorizeStep); config.map([ {route: ['', ':filter'], name: "", moduleId: 'welcome'} {route: 'home', name: "home", moduleId: 'home' auth:true} ]); this.router = router; } } class AuthorizeStep { run(routingContext, next) { if (routingContext.nextInstructions.some(i => i

@bindable changeHandler fires before bindings are done updating

穿精又带淫゛_ 提交于 2019-11-27 08:04:45
问题 The Code: App.js export class App { constructor() { this.widgets = [{ name: 'zero'}, {name: 'one'}, {name:'two'}]; this.shipment = { widget: this.widgets[1] }; } } App.html <template> <require from="./widget-picker"></require> <require from="./some-other-component"></require> <widget-picker widget.bind="shipment.widget" widgets.bind="widgets"></widget-picker> <some-other-component widget.bind="shipment.widget"/> </template> widget-picker.js import {bindable, bindingMode} from 'aurelia