Lij*_*raj 0 angular angular6 angular-input
我正在尝试创建这样的通用控件
动态控制
import { Component, Input } from '@angular/core';
@Component({
selector: 'ngo-button',
template: `<button [ngClass]=class type={{type}}>{{message}}</button>`,
styles: [`.one{border:solid 2px yellow} .two{background-color:pink} .three{
background-color: blue;
}`]
})
export class HelloComponent {
@Input() type: string = 'button';
@Input() class: string = 'one three';
@Input() message: string = 'submit';
}
Run Code Online (Sandbox Code Playgroud)
main-component.html
<ngo-button [class]='btn two' (click)='somefunc()'></ngo-button>
Run Code Online (Sandbox Code Playgroud)
现在我想将两个类传递给按钮,但是当我试图以这种方式传递它时,我得到了错误
[class] ='btn two'
我想,我们不允许在输入参数中添加空间,还有另一种实现方法吗?
小智 7
<ngo-button [class]="'btn two'" (click)='somefunc()'></ngo-button>
Run Code Online (Sandbox Code Playgroud)
Angular的默认语法。如果使用[input]符号,则必须在引号中提供一个字符串。
除此以外 :
<ngo-button class="btn two" (click)='somefunc()'></ngo-button>
Run Code Online (Sandbox Code Playgroud)
尽管我不得不说,但它真的不明白为什么您使用输入来提供组件的类。
| 归档时间: |
|
| 查看次数: |
47 次 |
| 最近记录: |