正如我"ngx-toastr": "^11.3.3"
在我的package.json中使用并在我的app.module.ts中导入的那样。
imports: [
AgmCoreModule.forRoot({ apiKey: 'AIzaSyC5gJ5x8Yw7qP_DqvNq3IdZi2WUSiDjskk' }),
BrowserAnimationsModule,
BrowserModule,
ToastrModule.forRoot({
timeOut: 1000,
positionClass: 'toast-bottom-right'
}),
]
在我的CompanyProfile.service.ts文件中,我使用了如下代码。
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { CustomerProfile } from '../_models/CustomerProfile';
import { CustomerUser } from '../_models/CustomerUser';
import { ToastrService } from 'ngx-toastr';
@Injectable({
providedIn: 'root'
})
export class CustomerProfileService {
private messageCustomerProfileSource: BehaviorSubject<CustomerProfile>;
public currentCustomerProfileMessage: Observable<CustomerProfile>;
constructor(private http: HttpClient, private toastr: ToastrService) {
this.messageCustomerProfileSource = new BehaviorSubject<CustomerProfile>(new CustomerProfile());
this.currentCustomerProfileMessage = this.messageCustomerProfileSource.asObservable();
}
CustomerUserAdd(_CustomerUser: CustomerUser, UserLogo: File) {
const fData = new FormData();
fData.append('Id', _CustomerUser.Id == null ? '' : _CustomerUser.Id.toString());
fData.append('CustomerId', _CustomerUser.CompanyId.toString());
fData.append('FirstName', _CustomerUser.FirstName);
fData.append('LastName', _CustomerUser.LastName);
if (UserLogo != null) {
fData.append('FileUpload', UserLogo, UserLogo.name);
}
const hdrs = new HttpHeaders().append('Content-Disposition', 'mulipart/form-data');
this.http.post(`CompanyProfile/RegisterCustomerUsers`, fData, { headers: hdrs })
.subscribe(this.Success, this.Error);
}
UpdateUsersPermissions(Id: number, Type: string, IsActive: boolean) {
const fData = new FormData();
fData.append('Id', Id.toString());
fData.append('Type', Type);
fData.append('IsActive', IsActive.toString());
this.http.post(`CompanyProfile/UpdateUsersPermissions`, fData)
.subscribe(this.Success, this.Error);
}
Error(data) {
this.toastr.error(data.errorMessage, 'Error !');
}
Success(data) {
this.toastr.success(data.errorMessage, 'Success !');
location.href = "/#/CustomerUsers";
}
}
因为它显示了以下错误,它没有按预期工作,而且我也需要location.href = "/#/CustomerUsers"
在 toastr 成功中添加。