Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度业力-没有MatDialogRef的提供程序_Angular_Typescript_Karma Jasmine_Karma Runner - Fatal编程技术网

Angular 角度业力-没有MatDialogRef的提供程序

Angular 角度业力-没有MatDialogRef的提供程序,angular,typescript,karma-jasmine,karma-runner,Angular,Typescript,Karma Jasmine,Karma Runner,当我尝试使用角度业力测试时,它显示如下 NullInjectorError: StaticInjectorError(DynamicTestModule)[ManageProblemsComponent -> MatDialogRef]: StaticInjectorError(Platform: core)[ManageProblemsComponent -> MatDialogRef]: NullInjectorError: No provider for MatDialog

当我尝试使用角度业力测试时,它显示如下

NullInjectorError: StaticInjectorError(DynamicTestModule)[ManageProblemsComponent -> MatDialogRef]: 
StaticInjectorError(Platform: core)[ManageProblemsComponent -> MatDialogRef]: 
NullInjectorError: No provider for MatDialogRef!
组成部分

import { Component, OnInit, Inject } from '@angular/core';
import { NbDialogRef, NB_WINDOW_CONTEXT } from '@nebular/theme';
import { ApiService } from '../../../../../app/services/api.service';
import { SmartTableData } from '../../../../@core/data/smart-table';
import { NbDialogService } from '@nebular/theme';
import { NbComponentStatus, NbGlobalPhysicalPosition, NbToastrService } from '@nebular/theme';
import { ToasterConfig } from 'angular2-toaster';
import 'style-loader!angular2-toaster/toaster.css';
import { AuthService } from '../../../../services/auth.service';
import { NgxSpinnerService } from "ngx-spinner";
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { DialogData } from '../../manage-alerts/manage-alerts.component';
import { Route, Router } from '@angular/router';

@Component({
  selector: 'ngx-manage-problems',
  templateUrl: './manage-problems.component.html',
  styleUrls: ['./manage-problems.component.scss']
})
export class ManageProblemsComponent  implements OnInit {
  title: String;
  myObject: any;
  VendorsComponentobject: any;
  CrewMembersComponentobject: any;
  crewMembers:any = [];
  vendorMembers:any = [];
  DeliveryAgentMembers:any = [];
  DeliveryAgentManagerMembers:any = [];
  AdminMembers:any = [];
  partialRefundStatus:any;
  partialAmount:any;
  issueData: any;

  refundStatus: boolean;
  refundReason: any = '';
  buttonStatus: boolean = true;
  submitClick: boolean = false;

  constructor(public dialogRef: MatDialogRef<ManageProblemsComponent>,
  @Inject(MAT_DIALOG_DATA) public data: DialogData, 
  private apiService: ApiService,
  private spinner: NgxSpinnerService,
  private toastrService: NbToastrService,
  public router: Router
    ) {
      this.issueData = data;
      this.partialRefundStatus = false;
  }

  currency:any;
  ngOnInit(){
    this.currency =localStorage.getItem('CurrencySymbol');
    localStorage.removeItem('issueDeatilsId');
    localStorage.removeItem('issueType'); 
  }

  manageQueue(): void {
    this.router.navigate(['/pages/orders/manage-queue',this.issueData.reporter._id])
    this.dialogRef.close();
    localStorage.setItem('issueDeatilsId',this.issueData._id)
    localStorage.setItem('issueType',this.issueData.type)
  }

  close(): void {
    this.dialogRef.close();
  }
  
 

  cancelissue(): void {
    
    this.spinner.show();
    const data2 = {
      status: "closed",
      actions: "resolved",
      _id : this.issueData._id
    }
   
    this.apiService.changeIssueStatus(data2).subscribe((res)=>{
      if(res.status == true){
        if(this.issueData.orderId && this.issueData.orderId._id){
          const data3 = {
            status: "cancelled",
            orderID : this.issueData.orderId._id
          }
          this.apiService.cancelOrder(data3).subscribe((res)=>{
            this.dialogRef.close('success');
            this.spinner.hide();
            if(res.status == true){
              this.showToast('success', '', 'Issue has been resolved successfully');
            } else {
                this.showToast('danger', '', 'Error');
            } 
          });
        } else {
          this.dialogRef.close('success');
          this.spinner.hide();
          this.showToast('success', '', 'Issue has been resolved successfully');
        }
      } else {
        this.dialogRef.close('success');
        this.spinner.hide();
        this.showToast('danger', '', 'Error');
      } 
    });
  }
  



 
 

}

从'@angular/core'导入{Component,OnInit,Inject};
从“@nebular/theme”导入{NbDialogRef,NB_WINDOW_CONTEXT};
从“../../../../app/services/api.service”导入{ApiService};
从“../../../../@core/data/smart table”导入{SmartTableData};
从“@nebular/theme”导入{NbDialogService};
从“@nebular/theme”导入{NbComponentStatus,NbGlobalPhysicalPosition,nbtoastarservice};
从“angular2 toaster”导入{ToasterConfig};
导入'样式加载器!angular2烤面包机/烤面包机.css';
从“../../../../services/auth.service”导入{AuthService};
从“ngx微调器”导入{NgxSpinnerService};
从“@angular/material”导入{MAT_DIALOG_DATA,MatDialogRef};
从“../../manage alerts/manage alerts.component”导入{DialogData};
从'@angular/Router'导入{Route,Router};
@组成部分({
选择器:“ngx管理问题”,
templateUrl:“./manageproblems.component.html”,
样式URL:['./管理问题.component.scss']
})
导出类管理器问题组件实现OnInit{
标题:字符串;
对象:任何;
供应商组件对象:任何;
乘员组件对象:任意;
船员:任何=[];
供应商成员:任意=[];
DeliveryAgentMembers:any=[];
DeliveryAgentManagerMembers:any=[];
AdminMembers:any=[];
部分退款状态:任何;
partialAmount:任何;
发布数据:任何;
状态:布尔;
退款理由:任何=“”;
buttonStatus:boolean=true;
submitClick:boolean=false;
构造函数(公共dialogRef:MatDialogRef,
@注入(MAT_DIALOG_DATA)公共数据:DialogData,
私人apiService:apiService,
私人微调器:NgxSpinnerService,
私人toastrService:NbToastrService,
公共路由器
) {
this.issueData=数据;
this.partialReturnStatus=false;
}
货币:任何;
恩戈尼尼特(){
this.currency=localStorage.getItem('CurrencySymbol');
localStorage.removietem('issuedatilsid');
localStorage.removietem('issueType');
}
manageQueue():void{
this.router.navigate(['/pages/orders/manage queue',this.issueData.reporter.\u id])
this.dialogRef.close();
localStorage.setItem('issueDatiLSID',this.issueData.\u id)
localStorage.setItem('issueType',this.issueData.type)
}
close():void{
this.dialogRef.close();
}
cancelissue():无效{
this.spinner.show();
常数数据2={
状态:“已关闭”,
行动:“已解决”,
_id:此。已发布数据。\u id
}
this.apiService.changeIssueStatus(data2.subscribe)((res)=>{
if(res.status==true){
if(this.issueData.orderId&&this.issueData.orderId.\u id){
常数数据3={
状态:“已取消”,
orderID:this.issueData.orderID.\u id
}
this.apiService.cancelOrder(data3.subscribe)(res)=>{
此.dialogRef.close('success');
this.spinner.hide();
if(res.status==true){
此.showtoos('success','problem has resolved successfully');
}否则{
这个。showtoos(‘危险’、‘错误’);
} 
});
}否则{
此.dialogRef.close('success');
this.spinner.hide();
此.showtoos('success','problem has resolved successfully');
}
}否则{
此.dialogRef.close('success');
this.spinner.hide();
这个。showtoos(‘危险’、‘错误’);
} 
});
}
}
规格ts

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ManageProblemsComponent } from './manage-problems.component';
import { NbCardModule } from '@nebular/theme';
import { FormsModule } from '@angular/forms';

describe('ManageProblemsComponent', () => {
  let component: ManageProblemsComponent;
  let fixture: ComponentFixture<ManageProblemsComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        NbCardModule,
        FormsModule
      ],
      declarations: [ ManageProblemsComponent ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ManageProblemsComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

从'@angular/core/testing'导入{async,ComponentFixture,TestBed};
从“/manageproblems.component”导入{ManageProblemsComponent};
从“@nebular/theme”导入{NbCardModule};
从'@angular/forms'导入{FormsModule};
描述('ManageProblemsComponent',()=>{
let组件:ManageProblemsComponent;
let夹具:组件夹具;
beforeach(异步(()=>{
TestBed.configureTestingModule({
进口:[
nbcard模块,
FormsModule
],
声明:[ManageProblemsComponent]
})
.compileComponents();
}));
在每个之前(()=>{
fixture=TestBed.createComponent(ManageProblemsComponent);
组件=fixture.componentInstance;
fixture.detectChanges();
});
它('应该创建',()=>{
expect(component.toBeTruthy();
});
});
当我添加时,
提供程序:[MatDialogRef]
,它显示
失败:无法解析MatDialogRef:(?,?,?)的所有参数。


谢谢

您需要在试验台

providers: [{ provide: MatDialogRef, useValue: {} }, { provide: MAT_DIALOG_DATA, useValue: data }]
例如,
providers:[{provide:MatDialogRef,useValue:{}}]


您可以使用useValue使用任何mockValue。您需要为测试床中的MatDialogRefMAT_DIALOG_数据提供模拟数据

providers: [{ provide: MatDialogRef, useValue: {} }, { provide: MAT_DIALOG_DATA, useValue: data }]

尝试导入MatDialogModule?当我添加它时,会显示
NullInjectorError:InjectionToken MatDialogData没有提供程序此错误…基本上,您需要在提供程序中提供所有依赖项,用于成功创建组件。此外,您还可以尝试导入MatDialogModule