Closed sayli-j closed 11 months ago
Can you post the code of the component to reproduce the error? (remove everything not necessary to reproduce it)
Thanks
submitClicked:boolean=false; filterForm: FormGroup; filters : any[] = []; page = 1; editId: string = ''; pageSize: number; totalRec:number; offset :number = 1; storeTypes : any[] = []; dropdownSettings = { singleSelection: false, text:"Types", selectAllText:'Select All', unSelectAllText:'UnSelect All', enableSearchFilter: false, labelKey:'title', primaryKey:'_id', enableCheckAll:false, badgeShowLimit:3 }; dataReceived:boolean=false; selectedPlan:any; loadCompleted:boolean=false; searchText:any; constructor(private route: ActivatedRoute,private router: Router,private modalService: NgbModal,private dataService : DataService, private changeDetector: ChangeDetectorRef,private spinner :NgxSpinnerService, private formBuilder: FormBuilder,private filterService : FilterService) { let ref=this; setTimeout(function(){ ref.dataService.getPricingDetails().subscribe( (response : any) => { ref.selectedPlan=response.data.plan },(error) => console.error(error), () => ref.loadCompleted = true) },500);
this.getFilters();
}
ngAfterViewChecked() {
this.changeDetector.detectChanges();
}
ngOnInit() { this.spinner.show(); this.createForm(); let id = this.route.snapshot.paramMap.get('id'); if(id){ this.editId=id; } this.spinner.hide(); } value = ''; update(value: string) { this.value = value.toLowerCase().split(" ").join("_"); } createForm() { this.filterForm = this.formBuilder.group({ 'title': this.formBuilder.control('',[Validators.required, Validators.maxLength(50)]), 'description': this.formBuilder.control('',[ Validators.maxLength(200)]), 'typeId':this.formBuilder.control([]) }); } get f() { return this.filterForm.controls; } get title(){ return this.filterForm.get('title'); }
get description(){ return this.filterForm.get('description'); }
getFilters(){ this.dataReceived=false; this.filterService.getStoreTypes(this.searchText).subscribe( (response : any) => { this.storeTypes = response.data.types; this.storeTypes.forEach(element=>{ if(!element.isActive){ element.title=element.title+' (Disabled)' } }) this.dataReceived=true; this.spinner.hide(); }, (err) => { this.dataReceived=true; Swal.fire('Oops...', err.error.message, 'error') this.spinner.hide(); } ) this.filterService.getFilters(this.page,this.searchText).subscribe( (response : any) => { this.filters = response.data.filters; // this.filters['storeType']=this.storeTypes; this.pageSize = response.data.limit; this.totalRec = response.data.totalCount; this.spinner.hide(); if(this.editId){ this.patchFiltersData() }
},
(err) => {
Swal.fire('Oops...', err.error.message, 'error')
this.spinner.hide();
}
)
} patchFiltersData(){ let selectedFilter:any; let selectedTypeId=[]; this.filters.forEach(val => { if(val._id == this.editId){ selectedFilter=val } }) if(this.storeTypes.length>0){ selectedFilter.typeIds.forEach(element=>{ let index = this.storeTypes.findIndex(a => a._id === element._id) selectedTypeId.push({ title:this.storeTypes[index].title, typeId:this.storeTypes[index].typeId, _id: this.storeTypes[index]._id, }) }) } this.filterForm.patchValue({ 'title': selectedFilter.title, 'description': selectedFilter.description, 'typeId':selectedTypeId }) this.value=selectedFilter.filterId }
saveFilter(){
if(!this.filterForm.invalid) {
this.submitClicked=true;
let datatoSend={
title: this.filterForm.value.title,
//description:this.filterForm.value.description,
}
if(this.filterForm.value.description){
datatoSend['description']=this.filterForm.value.description
}
let selectedTypeId=[];
let typeIdToSend=this.filterForm.value.typeId;
if(this.filterForm.value.typeId){
typeIdToSend.forEach(element => {
selectedTypeId.push(element._id)
});
datatoSend['typeId']=selectedTypeId;
}
this.filterService.addFilter(datatoSend).subscribe(
(response) => {
Swal.fire('Success', 'Filter added', 'success')
this.router.navigateByUrl(/admin/filter
)
this.getFilters();
//this.closeModal();
},
(err) => {
Swal.fire('Oops...', err.error.message, 'error')
}
)
}else{
Swal.fire('Oops!', 'Please enter valid data', 'error')
this.submitClicked=false;
}
}
editFilter() {
let unset= []
if(!this.filterForm.invalid) {
let datatoSend={
title: this.filterForm.value.title,
}
if(this.filterForm.value.description){
datatoSend['description']=this.filterForm.value.description
}else{
unset.push("description")
}
let selectedTypeId=[];
let typeIdToSend=this.filterForm.value.typeId;
if(this.filterForm.value.typeId){
typeIdToSend.forEach(element => {
selectedTypeId.push(element._id)
});
}
datatoSend['unset']=unset;
datatoSend['typeId']=selectedTypeId;
this.filterService.editFilter(datatoSend,this.editId).subscribe(
(response) => {
Swal.fire('Success', 'Filter edited', 'success')
this.submitClicked=true;
this.getFilters();
this.router.navigateByUrl(/admin/filter
)
/// this.closeModal();
},
(err) => {
Swal.fire('Oops...', err.error.message, 'error')
}
)
}else{
Swal.fire('Oops!', 'Please enter valid data', 'error')
this.submitClicked=false;
}
}
toggleFilter(index) { this.filterService.updateFilterStatus(this.filters[index]._id,!this.filters[index].isActive ).subscribe( (response : any)=> { this.getFilters(); Swal.fire('Success', this.filters[index].isActive == true? 'Filter disabled !' : 'Filter enabled !' , 'success') }, (err) => { Swal.fire('Oops...', err.error.message, 'error') } ) } onSubmit(){ if(!this.filterForm.invalid) { if (this.editId){ this.editFilter(); } else{ this.saveFilter(); } }else { Swal.fire('Oops!', 'Please enter valid data', 'error'); this.spinner.hide(); } }
I can't reproduce the error with that code. Could you take the file that throws the error, copy it to a new Angular project (ignore the reference errors) and see if you get the error there? If so then start removing blocks/code until there's only the bare minimum to reproduce it, then share it. Thanks.
Thank you for reporting an issue with SimonTest. When submitting an issue please include a snipet of code to reproduce the problem. Take the component file and delete everything not required to reproduce the error.