我在打字稿中构建了一个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不确定?该代码可能在元素呈现之前运行。 –