Search code examples
javascriptcssangulartypescriptobject-fit

Apply object-fit to an element with Typescript in Angular 2


Im trying to use object-fit for an element in my app. My IDE doesnt recognize this:

child.style.objectFit = 'cover';

For some reason. It has squigly lines under objectFit. And when i do this:

child.style.setProperty( 'object-fit', 'cover', '!important' );

It wont show up in the Inspector of my browser. So it doesnt apply the code.

Why does it behaves so strangely?


Solution

  • Apparently your IDE (and environment) can't recognize the typings properly. To overcome that you can try casting it before using:

    (child.style as any).objectFit = 'cover';