import { inject } from 'aurelia-framework';
import { Router } from 'aurelia-router';
import { HackerNewsApi } from '../../services/api';

@inject(Router, HackerNewsApi)
export class Item {
    item: any;
    comments: any[];

    private readonly router: Router;
    private readonly api: HackerNewsApi;

    constructor(router: Router, api: HackerNewsApi) {
        this.router = router;
        this.api = api;
    }

    async activate(params: any): Promise<void> {
        window.scrollTo(0, 0);

        if (params.id === undefined || isNaN(params.id) || params.id < 0) {
            this.router.navigateToRoute('news');
            return;
        }

        this.comments = [];
        this.item = await this.api.fetchItem(params.id);

        if (this.item.kids !== undefined && this.item.kids.length >= 1) {
            this.comments = await this.api.fetchItems(this.item.kids);
        }
    }
}

import { inject } from 'aurelia-framework';
import { Router } from 'aurelia-router';
import { HackerNewsApi } from '../../services/api';

@inject(Router, HackerNewsApi)
export class Item {
    id: number;
    item: any;
    comments: any[];

    private readonly router: Router;
    private readonly api: HackerNewsApi;

    constructor(router: Router, api: HackerNewsApi) {
        this.router = router;
        this.api = api;
    }

    async activate(params: any): Promise<void> {
        window.scrollTo(0, 0);

        if (params.id === undefined || isNaN(params.id) || params.id < 0) {
            this.router.navigateToRoute('news');
            return;
        }

        this.id = params.id;
        this.comments = [];

        this.item = await this.api.fetchItem(this.id);

        if (this.item.kids !== undefined && this.item.kids.length >= 1) {
            this.comments = await this.api.fetchItems(this.item.kids);
        }
    }
}

--- 
+++ 
@@ -4,7 +4,6 @@
 
 @inject(Router, HackerNewsApi)
 export class Item {
-    id: number;
     item: any;
     comments: any[];
 
@@ -24,10 +23,8 @@
             return;
         }
 
-        this.id = params.id;
         this.comments = [];
-
-        this.item = await this.api.fetchItem(this.id);
+        this.item = await this.api.fetchItem(params.id);
 
         if (this.item.kids !== undefined && this.item.kids.length >= 1) {
             this.comments = await this.api.fetchItems(this.item.kids);
Remove unnecessary class level variable in item page
