我的模板中有这个组件:
<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但它是未定义的...
我在这里错过了什么?
我正在尝试学习角度材料2,并#auto在自动完成中遇到了这个属性.我理解auto可以替换为任何文本,但为什么#之前需要一个这里auto有什么名称?
<md-input-container>
<input mdInput placeholder="State" [mdAutocomplete]="auto" [formControl]="stateCtrl">
</md-input-container>
<md-autocomplete #auto="mdAutocomplete">
^^^^ what is name of this property
<md-option *ngFor="let state of filteredStates | async" [value]="state">
{{ state }}
</md-option>
</md-autocomplete>
Run Code Online (Sandbox Code Playgroud)