Vheissu / aurelia-for-real-world-web-applications-book-feedback

Post feedback as issues here on Github for the Aurelia book. Be as descriptive and honest as you like.
15 stars 0 forks source link

parent vm in child vm #60

Open opcodewriter opened 8 years ago

opcodewriter commented 8 years ago

I'm sorry if it's already in the book, I haven't seen it.

The scenario is: you need the parent view-model instance in the child view-model. This is done by the Aurelia's DI magic which looks up in the DI containment hierarchy and gets the parent VM instance. I think it would be very helpful to talk in the book about Aurelia's DI containment hierarchy, how it works, how is Aurelia building the hierarchy, etc. And also maybe some advanced stuff like, how to change the default DI hierarchy if needed (I don't have an example yet).

import {inject} from 'aurelia-framework';
import {Parent} from  './parent'

@inject(Parent)
export class Child {
  constructor(parent) {
    this.parent = parent;
    console.log("hello from child, parent's name is", this.parent.name);
  }
}
opcodewriter commented 8 years ago

http://aurelia.io/docs.html#/aurelia/dependency-injection/1.0.0-beta.1.2.2/doc/article/dependency-injection-basics