cuốn sách gpt4 ai đã làm

css - 从组件方法中将样式应用于 Angular Toast

In lại Tác giả: Walker 123 更新时间:2023-11-28 01:53:56 26 4
mua khóa gpt4 Nike

我需要将样式应用到将在调用特定函数时使用的 toast。我该怎么做?

toast.service.ts

import { Injectable, OnInit } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

@Injectable()
export class ToastrService {

public toasterStatus: BehaviorSubject;

constructor() {
this.toasterStatus = new BehaviorSubject(null);
}
showToaster(type: string, content: string) {
const toasterObj: Message = { severity: type, detail: content };
this.toasterStatus.next(toasterObj);
}
}

export interface Message {
severity: String;
detail: String;
}

我的组件.ts

import { ToastrService } from '../../../toast.service';

@Thành phần({
selector: '...',
templateUrl: './my.component.html',
styleUrls: ['./my.component.css']
})
export class MyComponent implements OnInit, OnDestroy {
constructor(private logService: LogService,
private toastrService: ToastrService,){...}

ngOnInit() {

this.idSubscription$ = this.route.params.subscribe(params => {
this.id = +params['id'];
});
this.logService.debug(this.id);


// check for error
if (my.error) {
this.logService.error('Error retrieving report templates.', reportTemplatesState);
this.toastrService.showToaster('danger', 'Error retrieving report templates.');
}
});

//我需要在组件方法中将下面的样式应用到这个 toastrService 元素

我的.component.css

.toastSticky{ 
position: -webkit-sticky; /* Safari */
vị trí: dính;
trên cùng: 0;
}

câu trả lời hay nhất

您使用 tài liệu 执行此操作 :

MatSnackBarConfig
Configuration used when opening a snack-bar.

panelClass: string | string[] Extra CSS classes to be
added to the snack bar container.

关于css - 从组件方法中将样式应用于 Angular Toast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49753744/

26 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress