我在打字稿中構建了一個IONIC 2項目。我有以下的CSS:Typescript打擊scss風格屬性的麻煩
.bottle {
background: linear-gradient(0deg, pink 100%, white 0%);
}
,我想調整的線性梯度從pink
值,從Javascript/Typescript.I已經做了我的打字稿以下,但我得到了一個錯誤說, styleFile元素不存在於BottleFill上。我做錯了什麼?
import {Page, Alert, NavController} from 'ionic-angular';
@Page({
templateUrl: 'build/pages/hello-ionic/hello-ionic.html'
})
export class HelloIonicPage {
constructor(public nav: NavController) { }
updateDisplay(batteryPercentage){
var bottleFill = document.getElementsByClassName('bottle')[0];
if(percentage <= 100){
bottleFill.style.linerar-gradient.pink = batteryPercentage + '%';
batteryPercentage += 5;
}
}
}
更新:
完整的錯誤:使用ngOnInit使用元素選擇沒有工作
The property 'style' does not exist on type 'Element'
...
是bottleFill不確定?該代碼可能在元素呈現之前運行。 –