Change the style of an item from the Ionic 2 controller

My code is:

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

I have a mistake

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

How can I change css style from controller?

+4
source share
1 answer

document.querySelectorwill return the match of the first element with the type Element. You need to convert it to HTMLElement. Try the following:

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

Source: https://habr.com/ru/post/1680310/


All Articles