我正在加载一个组件并在加载后传递一个对象。
@Component({
selector:"formatter-component-cell",
directives:[NgSwitch,NgSwitchDefault],
template:`
<div #component ></div>`})
export class FormatterComponentCell {
@ViewChild('component', {read: ViewContainerRef}) component;
@Input() dataMapping:DataToConfigMap;4
@Input() gridMethods:GridMethodes;
cmpRef:ComponentRef<any>;
constructor(private resolver:ComponentResolver) {
}
ngOnInit() {
this.resolver.resolveComponent(TextBoxFormatter) .then((factory:ComponentFactory<any>) => {
this.cmpRef = this.component.createComponent(factory);
if (this.cmpRef) {
this.cmpRef.instance.rowData = this.dataMapping.rowData;
this.cmpRef.instance.config = this.dataMapping.config;
this.cmpRef.instance.gridMethods=this.gridMethods;
}
});
}
}
但是当我访问
时get name{return rowData[key];}
组件IE中的抛出表达式在检查后发生了变化。上一个值:'[object Object]'。当前值:'true'。并显示一些旧数据; 它奇怪的行为。
//动态组件
@Component({
selector: 'widget1',
template: `
<span style="width: 100%" (click)="toggleEdit($event)" *ngIf="!isOnEdit">{{name}}</span>
<input type="text" (keyup)="onKeyUp($event)" [(ngModel)]="name" checked="isChecked" *ngIf="isOnEdit">`})
export class TextBoxFormatter extends FormatterCellComponentBase
{
isOnEdit:boolean = false;
get name():string {
return this.rowData["Name"];
}
set name(val) {
this.rowData["Name"] = val;
}
constructor(private _service:GridService) {
super();
}
toggleEdit(e:Event) {
e.stopPropagation();
this.isOnEdit = !this.isOnEdit;
}
onKeyUp(e:KeyboardEvent) {
if (e.keyCode == 13) {
this.isOnEdit = false;
this.gridMethods.editRow(this.rowData);
}
}
}