我正在用 typescript 构建一个 IONIC 2 元素。我有以下 CSS:
.bottle {
background: linear-gradient(0deg, pink 100%, white 0%);
}
我想从 Javascript/Typescript 调整线性渐变上的 pink
值。我已经在我的 typescript 中完成了以下操作,但我收到一条错误消息说样式元素确实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;
}
}
}
更新:
完整错误:
The property 'style' does not exist on type 'Element'
使用 ngOnInit 来使用元素选择器不起作用...
最佳答案
也许你应该在 View 初始化后由 Angular 调用的 ngAfterViewInit 方法中检索 css: http://learnangular2.com/lifecycle/
关于css - 以 scss 样式属性为目标的 Typescript 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36023886/