第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Angular 2中獲取與ElementRef關(guān)聯(lián)的組件的參考

如何在Angular 2中獲取與ElementRef關(guān)聯(lián)的組件的參考

守著星空守著你 2019-11-15 10:59:22
我的模板中包含以下組件:<vector-editor  #scaleControl                [x]="scaleX"                [y]="scaleY"                [z]="scaleZ" >               </vector-editor>該vector-editor結(jié)構(gòu)如下:export class VerticeControlComponent implements OnInit{    @Input() x: number;    @Input() y: number;    @Input() z: number;    ...}在我的應(yīng)用程序中,我獲取了有關(guān)#scaleControl使用的參考@ViewChild('scaleControl') scaleControl: ElementRef;現(xiàn)在,如果我輸出scaleControl到控制臺,則會得到以下結(jié)果:可以看出,引用不是null,并且組件的所有屬性都在其中。我想訪問這些屬性,但是在代碼中,scaleControlis 的實(shí)際類型是ElementRef而不是VectorEditorControl在輸出中看到的。因此,我不允許TypeScript使用this.scaleControl.x。我也試過ElementRef像這樣var temp = <VectorEditorControl>this.scaleControl但我得到一個錯誤,告訴我,我不能投ElementRef來VectorEditorControl最后,我嘗試訪問,this.scaleControl.nativeElement但未定義...我在這里想念什么?
查看完整描述

3 回答

?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗 獲得超8個贊

在撰寫本文時,我建議使用以下方法:


@ViewChild('scaleControl') scaleControl: ElementRef<VerticeControlComponent>;

然后,您可以訪問這兩種類型。


ElementRef:使用scaleControl

VerticeControlComponent:使用scaleControl.nativeElement


查看完整回答
反對 回復(fù) 2019-11-15
  • 3 回答
  • 0 關(guān)注
  • 1177 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號