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

标签 css angular typescript

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

toast.service.ts

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

@Injectable()
export class ToastrService {

    public toasterStatus: BehaviorSubject<Message>;

    constructor() {
        this.toasterStatus = new BehaviorSubject<Message>(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';

@Component({
  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 */
  position: sticky;
  top: 0;
}

最佳答案

您使用 documentation 执行此操作 :

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/

相关文章:

html - IOS 7 safari 忽略视口(viewport)标签

css - PSD 到 HTML 以某种方式起作用,但实际上不起作用。我是新手

javascript - 如何在 snapshot.foreach 中访问超出其范围的变量值

angular - System.import 来自 JavaScript 或者特定于 Angular 2

typescript - 如何跳过多个泛型类的定义类型

HTML,如何检查是否看到 DIV(未溢出)?

javascript - 如何更改所选选项的背景颜色? (HTML)

angular - 编译 Angular 4 应用程序时出错 "__webpack_require__"

angular - 增强第三方库 Typescript

angular - 如何让组件在按 Angular 单击按钮时删除自身