мой сценарий выглядит следующим образом: У меня есть 3 компонента: MainComponent, Componenta, ComponentBElementRef изменилось после того, как событие щелчка
MainComponent является dymamic загрузка Componenta. Componenta есть кнопка, которая OnClick вызова MainComponent.addComponent (ComponentB)
export class MainLayout
{
constructor(private dcl: DynamicComponentLoader,private elementRef:ElementRef) {
///this will work fine
this.dcl.loadIntoLocation(ComponentA,elementRef);
}
addComponent(component:Type) {
///this will fail
this.dcl.loadIntoLocation(component, this.elememtRef,'child1');
}
}
Ошибка я получаю: Вы можете видеть, что ошибка формируют объект elementRef ....
Uncaught EXCEPTION: Error during evaluation of "click" ORIGINAL EXCEPTION: TypeError: Cannot read property '_view' of undefined ORIGINAL STACKTRACE: TypeError: Cannot read property '_view' of undefined at Object.internalView (http://localhost:63342/decisionApp/decision-modeling-ui/node_modules/angular2/bundles/angular2.dev.js:6236:19) at AppViewManager_.getNamedElementInComponentView (http://localhost:63342/decisionApp/decision-modeling-ui/node_modules/angular2/bundles/angular2.dev.js:11240:33) at DynamicComponentLoader_.loadIntoLocation (http://localhost:63342/decisionApp/decision-modeling-ui/node_modules/angular2/bundles/angular2.dev.js:14547:62) at MainLayout.resolveComponent (http://localhost:63342/decisionApp/decision-modeling-ui/app/playground/ui-composition/mainLayout.js:32:18) at ComponentsList.onClick (http://localhost:63342/decisionApp/decision-modeling-ui/app/playground/ui-composition/ComponentsList.js:25:20)
Зачем использовать глобальный var? Вы проезжаете и возвращаетесь к компоненту между ними? –
Я изменил свой вопрос, чтобы быть более ясным ... – almog
Видели ли вы, что у вас есть опечатка? 'this.elememtRef'! =' this.elementRef' –