사용자 정의 버튼을 만들고 싶다고합시다. 그래서 나는 구성 요소각도 4는 컴포넌트 템플릿에 선언 할 때 속성을 적용합니다 (포장 요소를 렌더링하지 않음)
import { Component, Input } from '@angular/core';
@Component({
selector: '[extended-button]',
template: `<button (click)="onClick($event)"></button>`,
styles: []
})
export class ExtendedButtonComponent {
@Input() disabled: boolean;
}
을 만들 그리고이 버튼의 인스턴스를 사용할 때 HTML에 선언하는 템플릿 내부의 버튼에 적용 할 때 나는 attibutes에게 I 유형을 원하는 :
<div extended-button class="some-nice-button"></div>
따라서이 결과는 다음과 같습니다 난 정말 <div>
태그를 렌더링하지 않으
<button class="some-nice-button" (click)="onClick($event)"></button>
. 어떤 아이디어를 달성하는 방법? 당신은, 당신과 같이 다른 구성 요소에 첨부 할 수있는이 custom-button
를 사용하고자 할 때 다음
import { Component, Input } from '@angular/core';
@Component({
selector: 'custom-button',
template: `<button [class]="className" (click)="onClick($event)>Custom Button</button>`
})
export class CustomButtonComponent {
@Input() className: string;
}
: 이것은 당신이 달성하지만, 아래의 코드 조각을보고 싶은 경우
안녕하세요, 감사에 대한 너의 답. 나는 이것을 정말로 찾고 있지 않다. 래핑 요소를 렌더링하고 싶지는 않습니다. html의 요소를 템플릿의 버튼에 적용 할 때 선언 할 속성을 원합니다. 어쩌면 지침이나 뭔가를 조사해야 할 것입니다. –
몇 시간 전에이 책에 대해 읽었습니다. 정말로 필요한 것은 ng-template이 렌더링되지 않도록 지시문과 Ng-template입니다. 행운을 빕니다 –