1
我想現值在我app.js視圖模型到自定義元素綁定,但我似乎無法得到時images
值從無極設置bind
正常工作。如何使用承諾將應用的視圖模型綁定到自定義元素?
app.js
:
@inject(Api)
export class App {
constructor(api) {
this.api = api;
}
. . .
activate() {
this.api.mockGet('gallery').then((images) => this.images = images);
}
}
我的自定義元素,如app.html
引用:
<featured-image images.bind="images"></featured-image>
我的自定義元素的視圖模型,featured-image.js
:
import {containerless, bindable} from 'aurelia-framework';
@containerless
export class FeaturedImage {
@bindable images = null;
attached() {
console.log(this.images);
}
}
this.images
總是undefined
。如果我將images
設置爲硬編碼數組,它將按預期工作。我究竟做錯了什麼?
非常有趣。這有效,但我想明白爲什麼。文檔中是否有參考? – Brandon
是的,有。 http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.1.4/doc/article/cheat-sheet/7「如果你想在你的系統之前執行自定義邏輯,實現這個鉤子可以選擇返回一個承諾,告訴路由器等待綁定並附加視圖,直到完成工作。「 –
Derp - 非常感謝您的幫助!我很感激。 – Brandon