Я пытаюсь загрузить дочерний компонент динамически на основе какого-либо события из родительского компонента. Я получаю некоторые ошибки компиляции в инструкции Import и в операторах ViewChild. Ниже приведены Не удалось импортировать ComponentResolver и ViewContainerRef
Ошибка № 1
import { Component, ComponentResolver, ViewContainerRef, ViewChild, } from 'angular2/core';
Error: Module "...node_modules/angular2/core" has no exported member ComponentResolver
Ошибка № 2
@ViewChild("childContainer", { read: ViewContainerRef }) childContainer: ViewContainerRef;
Error: Supplied parameters do not match any signature of call target
Ошибка № 3
this._cr.resolveComponent(ExtractorDetails).then(cmpFactory => {
let cmpRef = this.childContainer.createComponent(cmpFactory);
cmpRef.instance.QueueID = this.queueID;
});
Error: Property createComponent does not exist on type 'ViewContainerRef'
Мой файл package.json выглядит следующим образом:
{
"name": "ASP.NET",
"version": "0.0.0",
"dependencies": {
"angular/http": "2.0.0-rc.1",
"angular2": "2.0.0-beta.17",
"bootstrap": "^3.3.5",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"jquery": "^2.2.4",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"systemjs": "0.19.22",
"zone.js": "0.5.15"
},
"devDependencies": {
"gulp": "3.8.11",
"gulp-concat": "2.5.2",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "1.2.0",
"rimraf": "2.2.8"
}
}
Мой родительский компонент выглядит ниже import {Component, ComponentResolver, ViewContainerRef, ViewChild,} из 'angular2/core'; import {ExtractorDetails} из './ExtractorDetails'; ..
@Component({
selector: 'kendo-grid',
templateUrl: './HTML/Admin/KendoGrid.html',
providers: [Configuration, Constants],
directives: [Grid]
})
export class ExtractorGrid {
options: any;
rowObject: any;
extractorDetails: any;
public component: any;
queueID: number;
@ViewChild("childContainer", { read: ViewContainerRef }) childContainer: ViewContainerRef;
constructor(private configSetttings: Configuration, private constants: Constants, private viewContainer: ViewContainerRef, private _cr: ComponentResolver) {
this.setUpGridOptions();
}
onChange(event) {
this.rowObject = event.target;
this._cr.resolveComponent(ExtractorDetails).then(cmpFactory => {
let cmpRef = this.childContainer.createComponent(cmpFactory);
cmpRef.instance.QueueID = this.queueID;
});
}
....
}
Может кто-нибудь мне точку, которая angular2 версию мне нужно обратиться, если мне нужно использовать ComponentResolver и ViewContainerRef?
Я предлагаю вам использовать новые версии углов2, основанные на кандидате на выпуск 3 или даже 4. rc4 был только что выпущен https://github.com/angular/angular/blob/master/CHANGELOG.md (многие вещи сильно отличаются от бета-стадии) – Gabi
Обновлено с помощью RC3, «зависимости»: {«угловой/http»: «2.0.0-rc.1», «angular2»: «2.0.0-rc.3» , ...} все еще получают ту же ошибку. есть идеи ? – Krishnan
Вы изменили импорт из 'angular2/xxx' в' @ angular/xxx'? –