【发布时间】:2017-08-01 13:31:26
【问题描述】:
我是 Angular2/4 和 Angular 打字稿的新手。我想为角形材料设计 snackbar 设置样式,例如将背景颜色从黑色和字体颜色更改为其他颜色。
我该如何设计“snackbar”的样式?
我在服务/核心中有材料设计小吃栏,为了使其可用,我根据需要在每个组件中调用它。
如何在 Angular 2/4 中设置 Angular 2 材料设计“snackbar”的样式?我在下面包含了代码 sn-p:
服务/核心
import { Injectable, Inject } from '@angular/core';
import { Observable } from 'rxjs/Observable'
import { DOCUMENT } from'@angular/platform-browser';
import { MdDialog, MdDialogRef } from '@angular/material';
import { MdDialogConfig, ComponentType } from '@angular/material';
import {MdSnackBar} from '@angular/material';
constructor(
public dialog: MdDialog,
public snackBar: MdSnackBar,
@Inject(DOCUMENT) public doc: any ) {
dialog.afterOpen.subscribe((ref: MdDialogRef<any>) => {
if (!doc.body.classList.contains('no-scroll')) {
doc.body.classList.add('no-scroll');
}
});
dialog.afterAllClosed.subscribe(() => {
doc.body.classList.remove('no-scroll');
}); }
openSnackBar(message: string, action?: string) {
this.snackBar.open(message, action, {
duration: 4000,
}); }
wiz.components.ts ....
saveData(): void {
this.advisorClientModel.currentStep = this.currentStep;
this.advisorClientModel.clientId = this.faService.getClientId();
this.advisorClientModel.isMaxAmount = this.isMaximumAmount;
this.advisorClientModel.desiredLoanAmount = this.loanAmount;
this.advisorClientModel.maxLoanAmount = this.eligibleSelected.advanceAmount;
this.advisorClientModel.pledgedAccounts = this.getPledgedAccountsArray();
this.advisorClientModel.pledgedMarketValue = this.getPledgedMarkeValue();
this.faService.updateAdvisorClient( this.advisorClientModel )
.subscribe(
successModel => {
this.coreService.openSnackBar("Your Data Has been Saved");
this.navigateTo("fa/wiz" + (this.currentStep + 1));
},
error => {
this.onError(error);
}
);
}
【问题讨论】: