Angular 5 @Input width并适用于div

问题描述 投票:1回答:1

这很容易。尝试输入50%,50px,20rem等字符串作为宽度,然后将其应用于组件的html。

<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', ...

宽度完全被忽略了......?提前致谢。

html angular input
1个回答
1
投票

看起来你的问题是'width'(第二个)的引用。它是一个变量,所以不应该在引号中。我的例子:

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

© www.soinside.com 2019 - 2024. All rights reserved.