需要帮助理解以下语句中{read:ViewContainerRef}的含义.
@ViewChild('myname', {read: ViewContainerRef}) target;
Run Code Online (Sandbox Code Playgroud) 我的模板中有这个组件:
<vector-editor #scaleControl
[x]="scaleX"
[y]="scaleY"
[z]="scaleZ" >
</vector-editor>
Run Code Online (Sandbox Code Playgroud)
该vector-editor结构如下:
export class VerticeControlComponent implements OnInit
{
@Input() x: number;
@Input() y: number;
@Input() z: number;
...
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我抓住了对#scaleControl使用的引用
@ViewChild('scaleControl') scaleControl: ElementRef;
Run Code Online (Sandbox Code Playgroud)
现在,如果我输出scaleControl到控制台,我得到这个结果:
可以看出,引用不是null,并且我的组件的所有属性都在那里.我想访问这些属性,但在代码中实际的类型scaleControl是,ElementRef而不是VectorEditorControl在输出中看到.因此,我不允许使用TypeScript this.scaleControl.x.
我也试着ElementRef像这样投
var temp = <VectorEditorControl>this.scaleControl
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,告诉我,我不能投ElementRef来VectorEditorControl
最后,我试图访问,this.scaleControl.nativeElement但它是未定义的...
我在这里错过了什么?
angular ×2