In my angular 2 application, there is a component that contains an array of objects that passes the selected (pressed) one direct child component to it. This displays the data in more detail. I use the "SimpleChanges" function to view in this child component if the given object has changed to make another HTTP request to get related comments from the database.
If I try to build it using npm, I get an error:
app / displayEntry.component.ts (23,41): error TS2339: property 'entry' does not exist in type 'SimpleChanges'
If I just comment on this part, start npm and finally return it there and save, there is no more problem (there is no erro and it works). My question is, is there a way around this behavior, and can it cause any problems later, I do not foresee or should not just ignore it? Thanks for your help.
Parent component:
import { Component, OnInit } from '@angular/core'; import { entry } from './Objekte/entry'; import { entryService } from './entry.service' @Component({ templateUrl: 'app/Html_Templates/displayLastEntrys.template.html' }) export class displayLastEntrys implements OnInit{ public entrys : entry[]; private entryChoosen: boolean; private ChoosenEntry : entry; constructor ( private entryservice : entryService){ this.entryChoosen = false; } ngOnInit() : void { this.getData(); } getData() { this.entryservice.getFirstEntrys().then(entrys => this.entrys = entrys); } entryClicked(ent: entry){ this.entryChoosen = true; this.ChoosenEntry = ent; } leaveEntry () { this.entryChoosen = false; } voted( upordown : boolean ) { } }
Children's component:
import { Component, Input, Injectable, OnChanges , SimpleChanges, Output, EventEmitter} from '@angular/core'; import { entry} from './Objekte/entry'; import { entryService } from './entry.service'; import { comment } from './Objekte/comments'; @Component({ selector: 'display-entry', templateUrl: 'app/Html_Templates/displayEntry.template.html' }) export class displayComponent implements OnChanges{ @Input() public entry : entry; public comments : comment[]; private changecounter : number; constructor(private service : entryService) { this.changecounter = 0; } ngOnChanges(changes : SimpleChanges){ this.service.getComments(changes.entry.currentValue.id) .then(com => this.comments = com ) .catch(); this.entry.viewed++;
source share