Angular 错误类型错误:无法读取属性';sortChange';对于未定义,是否显示此错误?
Plz引导我,在加载此页面时,“错误类型错误:无法读取未定义的属性'sortChange',显示此错误,在模块和组件中声明所有,仅显示此错误 TSAngular 错误类型错误:无法读取属性';sortChange';对于未定义,是否显示此错误?,angular,typescript,angular8,angular9,Angular,Typescript,Angular8,Angular9,Plz引导我,在加载此页面时,“错误类型错误:无法读取未定义的属性'sortChange',显示此错误,在模块和组件中声明所有,仅显示此错误 TS 从'@angular/core'导入{Component,OnInit,ViewChild,ElementRef}; 从'@angular/cdk/collections'导入{SelectionModel}; 从“rxjs”导入{Observable,fromEvent,merge,Subscription,of};//RXJS 从“../../.
从'@angular/core'导入{Component,OnInit,ViewChild,ElementRef};
从'@angular/cdk/collections'导入{SelectionModel};
从“rxjs”导入{Observable,fromEvent,merge,Subscription,of};//RXJS
从“../../../../core/e-commerce”导入{CalendarDataSource};
从“../../../../../environments/environment”导入{environment};
从“ngx-toastr”导入{ToastrService};
从“../../../core/_base/crud”导入{LayoutUtilsService,MessageType,QueryParamsModel};
//NGRX
从'@ngrx/Store'导入{Store,actionsObject};
从“../../../../core/reducers”导入{AppState};
从'@ngx translate/core'导入{TranslateService};
从“@angular/material”导入{MatPaginator、MatSort、MatDialog、matsnakbar};
从“../../../../core/_base/layout”导入{LayoutConfigService,SubheaderService};
从“../../../../core/e-commerce”导入{CalendarModel、CalendarsPageRequested、OneCalendarDeleted、ManyCalendarDarsDeleted、CalendarsStatusUpdate、CalendarsReset};
从“../../../core/auth/”导入{AuthNoticeService,AuthService,Register,User,UserService};
从“@angular/Router”导入{ActivatedRoute,Router,RouterLinkWithHref};
从“rxjs/operators”导入{debounceTime、distinctUntilChanged、tap、skip、delay、take};
让customerdashurl=environment.customerdashboardurl;
让commonUrl=environment.commonUrl;
导出接口周期元素{
名称:字符串;
职位:编号;
重量:个数;
符号:字符串;
描述:字符串;
}
@组成部分({
选择器:“kt事件管理器”,
templateUrl:'./eventmanager.component.html',
样式URL:['./eventmanager.component.scss']
})
导出类EventmanagerComponent在NIT上实现{
数据源:CalendarDataSource;
displayedColumns=['accountId'、'accountName'、'companyName'、'properties'、'plans'、'subscribe'、'emailOut'、'smsOut'、'resync'、'action'];
expandedElement:PeriodiceElement | null;
@ViewChild(MatPaginator,{static:true})paginator:MatPaginator;
@ViewChild('sort1',{static:true})sort:MatSort;
//过滤字段
@ViewChild('searchInput',{static:true})searchInput:ElementRef;
filterStatus:字符串=“”;
filterType:字符串=“”;
//挑选
selection=新SelectionModel(true,[]);
templatesResult:CalendarModel[]=[];
私人订阅:订阅[]=[];
超级管理员:字符串;
shownorecords:boolean=false;
apicallcnt:number=0;
sendParams:any={};
searchcriteria:any={};
构造函数(公共对话框:MatDialog,
公共小吃店:Matsnakbar,
专用layoutUtilsService:layoutUtilsService,
私人翻译:翻译服务,
私家店,
专用路由器:路由器,
专用layoutConfigService:layoutConfigService,
私有用户服务:用户服务,
私人分标题服务:分标题服务,
私人toastr:ToastrService,
) { }
恩戈尼尼特(){
this.subheaderService.setTitle(this.translate.instant('Subscriptions');
this.store.dispatch(new CalendarsReset());
this.superadminId=localStorage.getItem('superadminId');
this.layoutConfigService.reloadConfigs();
//如果用户更改排序顺序,请重置回第一页。
const sortSubscription=this.sort.sortChange.subscribe(()=>(this.paginator.pageIndex=0));
这个.subscriptions.push(sortSubscription);
/*数据加载将在两种情况下触发:
-发生分页事件时=>this.paginator.page
-发生排序事件时=>this.sort.sortChange
**/
const paginatorSubscriptions=merge(this.sort.sortChange,this.paginator.page).pipe(
点击(()=>this.loadCustomerList())
)
.subscribe();
this.subscriptions.push(paginatorSubscriptions);
//过滤,绑定到searchInput
//const searchSubscription=fromEvent(this.searchInput.nativeElement,'keyup').pipe(
//debounceTime(50),//用户可以在输入框中快速键入,这可能会触发大量服务器请求。使用此运算符,我们将发出的服务器请求数量限制为每150ms最多一个
//distinctUntilChanged(),//此运算符将消除重复值
//点击(()=>{
//this.paginator.pageIndex=0;
//这个.loadCustomerList();
// })
// )
//.subscribe();
//this.subscriptions.push(searchSubscription);
//初始化数据源
this.dataSource=新的CalendarDataSource(this.store);
console.log(this.dataSource);
const entitiesSubscription=this.dataSource.entitySubject.pipe(
跳过(1),
distinctUntilChanged()
).订阅(res=>{
this.templatesResult=res;
这个.apicallcnt++;
if(this.templatesResult.length==0&&this.apicallcnt>2)
{this.shownorecords=true;}else{this.shownorecords=false;}
});
this.subscriptions.push(实体订阅);
//第一批
of(未定义)。管道(取(1),延迟(1000))。订阅(()=>{//删除此行,只需加载模拟
这个.loadCustomerList();
});//删除此行,只需加载模拟
}
LoadCustomerList(){
this.selection.clear();
const queryParams=新的QueryParamsModel(
此.filterConfiguration(),
这个排序方向,
这个,排序,活动,
this.paginator.pageIndex,
this.paginator.pageSize
);
//来自服务器的呼叫请求
this.store.dispatch(新的CalendarsPageRequested({page:queryParams}));
this.selection.clear();
}
过滤器配置():任何{
常量过滤器:any={};
const searchText:string=this.searchInput.nativeElement.value;
if(this.filterStatus&&this.filterStatus.length>0){
filter.status=+this.filterStatus;
}
if(this.filterType
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { SelectionModel } from '@angular/cdk/collections';
import { Observable,fromEvent, merge, Subscription, of } from 'rxjs';// RXJS
import { CalendarDataSource } from '../../../../core/e-commerce';
import { environment } from '../../../../../environments/environment';
import { ToastrService } from 'ngx-toastr';
import { LayoutUtilsService, MessageType, QueryParamsModel } from '../../../../core/_base/crud';
// NGRX
import { Store, ActionsSubject } from '@ngrx/store';
import { AppState } from '../../../../core/reducers';
import { TranslateService } from '@ngx-translate/core';
import { MatPaginator, MatSort, MatDialog,MatSnackBar } from '@angular/material';
import { LayoutConfigService, SubheaderService } from '../../../../core/_base/layout';
import { CalendarModel, CalendarsPageRequested, OneCalendarDeleted, ManyCalendarsDeleted, CalendarsStatusUpdated ,CalendarsReset} from '../../../../core/e-commerce';
import { AuthNoticeService, AuthService, Register, User , UserService } from '../../../../core/auth/';
import { ActivatedRoute, Router, RouterLinkWithHref } from '@angular/router';
import { debounceTime, distinctUntilChanged, tap, skip, delay, take } from 'rxjs/operators';
let customerdashurl = environment.customerdashboardurl;
let commonUrl = environment.commonUrl;
export interface PeriodicElement {
name: string;
position: number;
weight: number;
symbol: string;
description: string;
}
@Component({
selector: 'kt-eventmanager',
templateUrl: './eventmanager.component.html',
styleUrls: ['./eventmanager.component.scss']
})
export class EventmanagerComponent implements OnInit {
dataSource:CalendarDataSource;
displayedColumns = ['accountId','accountName','companyName','properties','plans','subscribe','emailOut','smsOut','resync','action'];
expandedElement: PeriodicElement | null;
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
@ViewChild('sort1', {static: true}) sort: MatSort;
// Filter fields
@ViewChild('searchInput', {static: true}) searchInput: ElementRef;
filterStatus: string = '';
filterType: string = '';
// Selection
selection = new SelectionModel<CalendarModel>(true, []);
templatesResult: CalendarModel[] = [];
private subscriptions: Subscription[] = [];
superadminId:string;
shownorecords:boolean=false;
apicallcnt:number=0;
sendParams:any={};
searchcriteria:any={};
constructor(public dialog: MatDialog,
public snackBar: MatSnackBar,
private layoutUtilsService: LayoutUtilsService,
private translate: TranslateService,
private store: Store<AppState>,
private router: Router,
private layoutConfigService: LayoutConfigService,
private userService: UserService,
private subheaderService: SubheaderService,
private toastr:ToastrService,
) { }
ngOnInit() {
this.subheaderService.setTitle(this.translate.instant('Subscriptions'));
this.store.dispatch(new CalendarsReset());
this.superadminId = localStorage.getItem('superadminId');
this.layoutConfigService.reloadConfigs();
// If the user changes the sort order, reset back to the first page.
const sortSubscription = this.sort.sortChange.subscribe(() => (this.paginator.pageIndex = 0));
this.subscriptions.push(sortSubscription);
/* Data load will be triggered in two cases:
- when a pagination event occurs => this.paginator.page
- when a sort event occurs => this.sort.sortChange
**/
const paginatorSubscriptions = merge(this.sort.sortChange, this.paginator.page).pipe(
tap(() => this.loadCustomersList())
)
.subscribe();
this.subscriptions.push(paginatorSubscriptions);
// Filtration, bind to searchInput
// const searchSubscription = fromEvent(this.searchInput.nativeElement, 'keyup').pipe(
// debounceTime(50), // The user can type quite quickly in the input box, and that could trigger a lot of server requests. With this operator, we are limiting the amount of server requests emitted to a maximum of one every 150ms
// distinctUntilChanged(), // This operator will eliminate duplicate values
// tap(() => {
// this.paginator.pageIndex = 0;
// this.loadCustomersList();
// })
// )
// .subscribe();
// this.subscriptions.push(searchSubscription);
// Init DataSource
this.dataSource = new CalendarDataSource(this.store);
console.log(this.dataSource);
const entitiesSubscription = this.dataSource.entitySubject.pipe(
skip(1),
distinctUntilChanged()
).subscribe(res => {
this.templatesResult = res;
this.apicallcnt++;
if(this.templatesResult.length == 0 && this.apicallcnt>2)
{this.shownorecords = true;}else{this.shownorecords=false;}
});
this.subscriptions.push(entitiesSubscription);
// First load
of(undefined).pipe(take(1), delay(1000)).subscribe(() => { // Remove this line, just loading imitation
this.loadCustomersList();
}); // Remove this line, just loading imitation
}
loadCustomersList() {
this.selection.clear();
const queryParams = new QueryParamsModel(
this.filterConfiguration(),
this.sort.direction,
this.sort.active,
this.paginator.pageIndex,
this.paginator.pageSize
);
// Call request from server
this.store.dispatch(new CalendarsPageRequested({ page: queryParams }));
this.selection.clear();
}
filterConfiguration(): any {
const filter: any = {};
const searchText: string = this.searchInput.nativeElement.value;
if (this.filterStatus && this.filterStatus.length > 0) {
filter.status = +this.filterStatus;
}
if (this.filterType && this.filterType.length > 0) {
filter.type = +this.filterType;
}
filter.accountName = searchText;
if (!searchText) {
return filter;
}
filter.email = searchText;
filter.companyName = searchText;
// filter.userName = searchText;
// filter.id = searchText;
return filter;
}
}