Angular Toast 구성 요소 개요
Ignite UI for Angular 자동 숨김, 비대화형이며 사용자가 해제할 수 없는 정보 및 경고 메시지를 제공합니다. 알림은 페이지 하단, 중간 또는 상단에 표시할 수 있습니다.
Angular 토스트 예
Ignite UI for Angular Toast 시작하기
Ignite UI for Angular Toast 구성 요소를 시작하려면 먼저 Ignite UI for Angular 설치해야 합니다. 기존 Angular 애플리케이션에서 다음 명령을 입력합니다.
ng add igniteui-angular
cmd
Ignite UI for Angular에 대한 전체 소개는 시작 항목을 참조하십시오.
다음 단계는 IgxToastModule
당신의 app.module.ts 파일.
// app.module.ts
...
import { IgxToastModule } from 'igniteui-angular';
// import { IgxToastModule } from '@infragistics/igniteui-angular'; for licensed package
@NgModule({
...
imports: [..., IgxToastModule],
...
})
export class AppModule {}
typescript
또는 16.0.0
부터 IgxToastComponent
독립형 종속성으로 가져올 수 있습니다.
// home.component.ts
import { IgxToastComponent, IgxButtonDirective } from 'igniteui-angular';
// import { IgxToastComponent, IgxButtonDirective } from '@infragistics/igniteui-angular'; for licensed package
@Component({
selector: 'app-home',
template: `
<button igxButton="contained" (click)="toast.open()">Show notification</button>
<igx-toast #toast>Notification displayed</igx-toast>
`,
styleUrls: ['home.component.scss'],
standalone: true,
imports: [IgxToastComponent, IgxButtonDirective]
/* or imports: [IgxTimePickerComponent, IgxButtonDirective] */
})
export class HomeComponent {
public time: Date;
}
typescript
이제 Ignite UI for Angular 가져왔으므로 igx-toast
구성 요소를 사용할 수 있습니다.
Angular 토스트 사용하기
토스트 보여주기
토스트 구성 요소를 표시하려면 open()
메서드를 사용하고 버튼 클릭 시 호출합니다. 요소 내부에 토스트 콘텐츠를 전달할 수 있습니다.
<!--sample.component.html-->
<button igxButton="contained" (click)="toast.open()">Show notification</button>
<igx-toast #toast>Notification displayed</igx-toast>
html
알림 내용을 설정하는 또 다른 방법은 메시지를 open()
메서드에 매개 변수로 직접 전달하는 것입니다.
<!--sample.component.html-->
<button igxButton="contained" (click)="toast.open('Notification displayed')">Show notification</button>
<igx-toast #toast></igx-toast>
html
open()
메소드는 AppComponent 파일에서 메시지 값을 관리하는 데 사용될 수도 있습니다.
// app.component.ts
@ViewChild('toast', { read: IgxToastComponent }) public toast: IgxToastComponent;
public message: any;
public ngOnInit() {
this.message = 'Display message';
}
public showMessage() {
this.toast.open(this.message);
}
typescript
예
숨기기/자동 숨기기
일단 열리면 토스트는 처음에 4000밀리초로 설정된 displayTime
입력에 지정된 기간 후에 사라집니다. 이 동작은 기본적으로 활성화되어 있지만 autoHide
false로 설정하여 변경할 수 있습니다. 이렇게 하면 토스트가 계속 보입니다. toast close()
메서드를 사용하면 구성 요소를 닫을 수 있습니다.
<!--sample.component.html-->
<button igxButton="contained" (click)="toast.open()">Show Toast</button>
<button igxButton="contained" (click)="toast.close()">Hide Toast</button>
<igx-toast #toast [autoHide]="false">Notification displayed</igx-toast>
html
샘플이 올바르게 구성된 경우 표시 버튼을 클릭하면 토스트가 나타납니다. 첫 번째 구성 요소의 경우 자동 숨기기 기능이 비활성화되고 '숨기기' 버튼을 클릭하면 토스트가 사라집니다. 다른 두 구성 요소에서는 open()
메서드를 통해 다양한 메시지를 전달하고 콘텐츠 프로젝션을 사용하는 방법을 실제로 확인할 수 있습니다.
표시 시간
displayTime
사용하고 밀리초 단위의 간격으로 설정하여 토스트 구성 요소가 표시되는 시간을 구성합니다.
<!--sample.component.html-->
<button igxButton="contained" (click)="toast.open()">Show notification</button>
<igx-toast #toast displayTime="1000">Notification displayed</igx-toast>
html
샘플이 올바르게 구성되면 토스트 자동이 더 빨리 숨겨집니다.
포지셔닝
positionSettings
속성을 사용하여 토스트가 표시되는 위치를 구성합니다. 기본적으로 페이지 하단에 표시됩니다. 아래 샘플에서는 상단 위치에 알림이 표시되도록 설정했습니다.
<!--sample.component.html-->
<div>
<button igxButton="contained" (click)="open(toast)">Show notification on top</button>
<igx-toast #toast>Notification displayed</igx-toast>
</div>
html
// sample.component.ts
import { VerticalAlignment } from 'igniteui-angular';
// import { VerticalAlignment } from '@infragistics/igniteui-angular'; for licensed package
...
public open(toast) {
toast.positionSettings.verticalDirection = VerticalAlignment.Top;
toast.open();
}
...
typescript
스타일링
토스트 스타일링을 시작하려면 모든 테마 기능과 구성 요소 믹스인이 있는 인덱스 파일을 가져와야 합니다.
@use "igniteui-angular/theming" as *;
// IMPORTANT: Prior to Ignite UI for Angular version 13 use:
// @import '~igniteui-angular/lib/core/styles/themes/index';
scss
가장 간단한 접근 방식에 따라 를 확장하고 toast-theme
및 $text-color
$border-radius
매개 변수를 제공하는 $background
새 테마를 만듭니다.
$custom-toast-theme: toast-theme(
$text-color: #ffcd0f,
$background: #292826,
$border-radius: 12px
);
scss
우리가 방금 한 것처럼 색상 값을 하드 코딩하는 대신, and color
함수를 사용하여 palette
색상 측면에서 더 큰 유연성을 얻을 수 있습니다. 사용 방법에 대한 자세한 지침은 항목을 참조하십시오 Palettes
.
마지막 단계는 사용자 정의 토스트 테마를 전달하는 것입니다.
@include css-vars($custom-toast-theme);
scss
데모
API 참조
추가 리소스
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.