Reputation: 1
Trying to inject ViewSlot
into a skeleton based esnext project, the following error shows up in the browser. I have just created a simple project with the CLI based on systemjs
and I see the same thing.
vendor-bundle.js:1398 Unhandled rejection Error: Error invoking ViewSlot. Check the inner error for details.
Inner Error:
Message: Cannot set property ‘viewSlot’ of undefined``
From a modified CLI generated app, this reproduces the same problem I see in the real app,
import { BoundViewFactory, ViewSlot, customAttribute, templateController, inject } from 'aurelia-framework';
@inject(ViewSlot)
export class App {
constructor(viewSlot) {
this.message = 'Hello World!';
this.viewSlot = viewSlot;
}
}
Upvotes: 0
Views: 108
Reputation: 583
I think the @ViewSlot
should not be used as a decorator but as a class.
For example, let viewSlot = new ViewSlot(container, true);
Where the container is an HTML element.
Upvotes: 0
Reputation: 10897
I think the problem is that ViewSlot is supposed to be used with Custom Elements, not with pages. I don't have any problem injecting ViewSlot in to a Custom Element, but it fails every time for me when I try to use it on a page component.
The problem is that a ViewSlot
instance expects an anchor Node to be passed to it, but a page doesn't have an anchor Node. Aurelia passes undefined
for the anchor
property, and then ViewSlot
tries to set the viewSlot
property of the undefined value, and that fails.
Upvotes: 1