2

This has to be easy. Trying to input a string like 50%, 50px, 20rem ... as a width and then apply it to the html for the component.

<test title="frump" width="50%"></test>

export class test {
  @Input() title: string;
  @Input() width: string;
       ...
  getWidth() {
    return this.width;
  }

<div [ngStyle]="{'width.px': 'getWidth()', ... or
<div [ngStyle]="{'width': 'width', ...

The width is being totally ignored... ? Thanks in advance.

1
  • <div [ngStyle]="{'width': width, ... or <div [style.width]="width". Commented Feb 5, 2018 at 19:22

1 Answer 1

2

Looks like your problem is the quotations around 'width' (the second one). It's a variable so should not be in quotes. My example:

https://stackblitz.com/edit/angular-tgqahd?file=app%2Fapp.component.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.