0

I have a parent component and child component where I am using child component's selector to render it in parent component.

my child component html:

<div class="main-container" [ngStyle]="{'transform': 'scaleX(widthScale) scaleY(heightScale)'}">
    <img src="../../assets/svg/kiln-main.jpg" class="kiln-image">
    <svg id="area2"></svg>
    <svg id="area"></svg>
</div>

child component ts:

@Input() widthScale:string;
@Input() heightScale:string;

I want to apply "transform:scalex() scaley()" to child based on the values from the parent.

my parent:

<app-child [widthScale]="0.5" [heightScale]="0.5"></app-child>

The above code somehow isnt working.How to apply values to css property "transform" here?

1 Answer 1

1

You can create a method in the child as follows:

  getTransformStyle() {
    let styles = {
      transform: `scaleX(${this.widthScale}) scaleY(${this.heightScale})`,
    };
    return styles;
  }

Use it in child html as follows:

<div class="main-container" [ngStyle]="getTransformStyle()">
  <img src="../../assets/svg/kiln-main.jpg" class="kiln-image" />
  <svg id="area2"></svg>
  <svg id="area"></svg>
</div>

You can refer to the child as follows:

<app-child [widthScale]="'0.5'" [heightScale]="'0.5'"></app-child>

Working example: https://stackblitz.com/edit/angular-ivy-gaohfo

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.