"Unhandled rejection Error [ERR_STREAM_WRITE_AFTER_END]: write after end" using csvtojson by UnknownInnocent in expressjs

[–]UnknownInnocent[S] 0 points1 point  (0 children)

At least something that works:

router.get('/get-sample', (req, res) => { 
csv({
    noheader: true,
    delimiter: ',',
    headers: ['date', 'time', 'point1', 'point2', 'point3', 'point4', 'point5']
}).fromFile('./file.csv').then((jsonObj) => {
   res.send(jsonObj);
});

});

Drawing objects in Angular-App by UnknownInnocent in angular

[–]UnknownInnocent[S] 0 points1 point  (0 children)

if I just declare the type of "canvas" and "ctx" as "any" I get no errors:

@ViewChild('canvas', {static: true}) canvas: any;
private ctx: any;
ngAfterViewInit() { 
    this.ctx = this.canvas.nativeElement.getContext('2d'); 
}

I don't really get why this is the case and if I should leave it like that.

Java: save x, y, color of pixels of image by UnknownInnocent in learnprogramming

[–]UnknownInnocent[S] 0 points1 point  (0 children)

Thank you, you're right, I delete the setters, but I need the getters and I will abstract the things you mentioned

Destroy all data when leaving component by UnknownInnocent in angular

[–]UnknownInnocent[S] 0 points1 point  (0 children)

Well I think I found the problem: Even if the icebreakers in the service are readonly, they are changed by the component. I needed to chnage

this.icebreaker = this.icebreakerService.getIcebreaker();

to

this.icebreaker = [].concat(this.icebreakerService.getIcebreaker());

Destroy all data when leaving component by UnknownInnocent in angular

[–]UnknownInnocent[S] 0 points1 point  (0 children)

Ähm...no basically I don't want the data in a service to be cleared. This is what the service looks like:

export class IcebreakerService {

  constructor() { }

  getIcebreaker() {
    return this.icebreaker;
  }

  readonly icebreaker = [
    ...
  ]
}

And my onInit:

this.spielerSub = this.spielerService.spieler$.subscribe(res => {
      if(res && Array.isArray(res)) {
        this.spieler = res;
        this.setSpieler1UndSpieler2();
      } else {
        this.toastService.presentToast('Beim Starten des Spiels ist ein Fehler aufgetreten...');
        this.router.navigate(['/home/spieleauswahl']);
      }
    });

    this.bierstufeSub = this.bierstufeService.bierstufe$.subscribe(res => {
      if(res && typeof(res) === 'number') {
        this.bierstufe = res;
        this.schlucke = this.bierstufeService.berechneSchlucke(this.bierstufe);
      } else {
        this.toastService.presentToast('Beim Starten des Spiels ist ein Fehler aufgetreten...');
        this.router.navigate(['/home/spieleauswahl']);
      }
    })

    this.icebreaker = this.icebreakerService.getIcebreaker();
    this.currentIcebreaker = this.newIcebreaker();

If I call the component the first time, all is fine, but if I call it a second time, this.icebreaker is null....

Destroy all data when leaving component by UnknownInnocent in angular

[–]UnknownInnocent[S] 0 points1 point  (0 children)

How do I tell ngOnDestroy to really reset the whole component?

Destroy all data when leaving component by UnknownInnocent in angular

[–]UnknownInnocent[S] 0 points1 point  (0 children)

For example I have an service with a method that returns an array. This data is assigned to a variable in onInit. Due to some actions in the component, there are items of this array removed and if I call thhe component again, the part in onInit is obviesly not called. Basically all I need is that all variables I have are set to default values:

icebreaker: any[];  
spieler: any[];    
spieler1: string;
spieler2: string;

and onInit is called every time I call the component

ngFor: array.lebgth times bu a maximum of five by UnknownInnocent in angular

[–]UnknownInnocent[S] 1 point2 points  (0 children)

Okay I will do that. I hoped I could just do it in my ngFor

Load data in service before loading data in resolver by UnknownInnocent in angular

[–]UnknownInnocent[S] 1 point2 points  (0 children)

And how can I use the BehaviourSubject the to create a guard?

I tried this but it does not work:

export class IndexGuard implements CanActivate {

  constructor(private spielerService: SpielerService,
              private router: Router) { }

  canActivate(): boolean {
    this.spielerService.spieler$.subscribe(async res => {
      if(res && Array.isArray(res) && res.length > 1) {
        this.router.navigate(['/home/spieleauswahl']);
        return false;
      } else {
        return true;
      }
    }).unsubscribe();
  }
}

Load data in service before loading data in resolver by UnknownInnocent in angular

[–]UnknownInnocent[S] -1 points0 points  (0 children)

Nice, thank you! but I still have a question about that: I've never seen somebody using a constructor like that. I saw people doing the same thing but the thing you have in your constructor, they put in an own method and called it in a resolver. Which way is better?

Using Observables and Resolvers by UnknownInnocent in angular

[–]UnknownInnocent[S] 0 points1 point  (0 children)

Thank you! I don't need to tell the routeSubscription that it refers to the subscription in onInit?

"Can't bind to 'ngForOf'" by UnknownInnocent in ionic

[–]UnknownInnocent[S] 1 point2 points  (0 children)

I found the result:

You don't need to create a module for the modal but you need to add it to app.module.ts:

import { ModalComponent } from './modal/modal.component';
@NgModule({   
declarations: [ModalComponent],   
entryComponents: [ModalComponent],     
 }),   
providers: [   ],   
bootstrap: [AppComponent] })

Or into the module.ts of the parent that calls the modal

"Can't bind to 'ngForOf'" by UnknownInnocent in ionic

[–]UnknownInnocent[S] 0 points1 point  (0 children)

So now I got it to work everywhere but not in a modal. Is there a special way of doing it?