angular - 从 Controller Ionic 2 更改元素样式

标签 angular ionic-framework ionic2

我的代码:

document.querySelector(".myTabs .line")[0].style.left = '30%' ;

我有错误

undefined is not an object (evaluating 'document.querySelector(".myTabs .line")[0].style')

我如何从 Controller 更改 css 样式?

最佳答案

document.querySelector 将返回第一个匹配类型为 Element 的元素。您需要将其转换为 HTMLElement。试试这个:

let elm = <HTMLElement>document.querySelector(".myTabs .line");
elm.style.left = '30%'

关于angular - 从 Controller Ionic 2 更改元素样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44802728/

相关文章:

Angular 4如何应用动态样式?

javascript - 如何在 zone.js 中打印当前区域的路径

angular - Ionic 2 在应用程序启动后重定向到另一个页面

angular-cli:使用环境变量的条件导入

css - Ionic 中的响应式方形网格

angularjs - 如果用户已经登录 ionic ,如何跳过登录页面

angularjs - 如何从左向右滑动 Ionic 列表项?

html - 如何拥有更小的按钮 css

npm - 为什么 Yarn 不将所有可执行文件安装在 .bin 文件夹中?

ionic-framework - ionic Auth0 错误 : "Cannot read property ' isAvailable' of undefined"