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

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

無法在“窗口”上執(zhí)行“getComputedStyle”:參數(shù) 1 不是“元素”類型。

無法在“窗口”上執(zhí)行“getComputedStyle”:參數(shù) 1 不是“元素”類型。

牛魔王的故事 2022-10-27 14:51:59
我一直在 StackOverflow 和 Google 中尋找一段時間,但無法真正找到解決我的問題的方法。就這樣吧。我通過@ViewChildren('labelSquare') public labelIcon: QueryList<HTMLSpanElement>;裝飾器在 DOM 中有一組元素。在 HTML 中,我有以下內(nèi)容來綁定它: <span class="status-item" *ngFor="let status of statusList">     <div *ngIf="status.state !== 'Starting' &&                 status.state !== 'Stopping' &&                 status.state !== 'Synchronising' &&                 status.state !== 'EmergencyStop'"     >       <div class="status">         <span #labelSquare class="status-square fas fa-square {{ status.state }}"></span>         <span class="status-name">{{ status.text }}</span>       </div>     </div> </span>我從中得到了一個包含 58 個跨度元素的數(shù)組,現(xiàn)在想要附加一個比當(dāng)前背景顏色深 10% 的邊框。因此,我map為此使用了一個:if (this.labelIcon) {     this.labelIcon.map((icon: HTMLSpanElement) => {         const element = window.getComputedStyle(icon);         icon.setAttribute('style', `border: 1px solid ${ColorUtil.darkenBorderFromBackground(element.color)}`);     }); }我的ColorUtil.darkenBorderFromBackground()簡單回歸return darken(${backgroundColor}, 10%);(使用模板字符串,無法弄清楚如何在 StackOverflow 中格式化。我的問題是現(xiàn)在我得到了一個TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.誰能幫我嗎?
查看完整描述

1 回答

?
幕布斯7119047

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

Angular 返回一個ElementRef非 DOM 元素。

ElementRef有一個稱為nativeElementDOM 元素的屬性。所以icon改變icon.nativeElement內(nèi)部window.getComputedStyle()

請注意,您的打字稿界面也需要在 map 方法內(nèi)進行更改。

例如

if (this.labelIcon) {

 this.labelIcon.map((icon: ElementRef) => { // Not sure if ElementRef is a valid interface in Angular

     const element = window.getComputedStyle(icon.nativeElement);

     icon.setAttribute('style', `border: 1px solid ${ColorUtil.darkenBorderFromBackground(element.color)}`);

 });

}


查看完整回答
反對 回復(fù) 2022-10-27
  • 1 回答
  • 0 關(guān)注
  • 577 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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