首页 文章

Angular2 / Ionic 2动态组件属性

提问于
浏览
0

我想就这个问题寻求帮助 . 我正在研究角度2和离子的动态组件:请检查下面的场景 .

我有组件名称按钮组件:

<button-component [label]="I'm a button" **small**></button-component>

small - 必须在按钮元素中动态输入,如 biglarge .

在按钮组件视图文件里面我有:

<button "the single  attribute must appear here like small">{{label}}</button>

输出将是 <button small>I'm a button</button>

我尝试了角度2中的所有属性绑定,但这是离子属性 .

如何使用离子2和角度2来执行此操作 . 通过动态使用单个属性属性 .

提前致谢 .

1 回答

  • 2

    与Angular 2相同,只需发送 size 属性并将其设置为 small

    <button-component label="'I'm a button'" size="'small'"></button-component>
    

    然后在你的按钮组件中:

    @Input() size;
    

    并在您的模板中:

    <button [class]="size">{{label}}</button>
    

    并在CSS中声明所需的样式,例如:

    .small {
    ...
    }
    
    .big {
    ..
    }
    

相关问题