Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant make ngOnInit work #327

Open
phil123456 opened this issue Mar 30, 2017 · 6 comments
Open

cant make ngOnInit work #327

phil123456 opened this issue Mar 30, 2017 · 6 comments

Comments

@phil123456
Copy link

Hi,

I get something very strange with this seed

TS6133: 'OnInit' is declared but never used.

but I got ngOnInit() in my code (that used to be working)

if I comment OnInit then it compiles but my ngOnInit are never called

tried to dig this in google but cant find anything

any idea ? am I missing something ?

thanks

@Foxandxss
Copy link
Member

Uh, interesting, can I see code? Is that error from the linter or ts?

@phil123456
Copy link
Author

phil123456 commented Mar 30, 2017

so with OnInit

[at-loader] Checking started in a separate process...

[at-loader] Checking finished with 1 errors
Error in bail mode: [at-loader] ./src/app/app.component.ts:1:32
    TS6133: 'OnInit' is declared but never used.

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.9.2
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE

with OnInit commented

WARNING in ./src/app/app.component.ts
[31, 5]: Implement lifecycle hook interface OnInit for method ngOnInit in class AppComponent (https://goo.gl/w1Nwk3)

 @ ./src/app/app.module.ts 20:22-48
 @ ./src/main.ts
import { Component, ViewChild, /*OnInit*/ } from '@angular/core';
import { Router } from '@angular/router';

import { DialogComponent } from './components/dialog/dialog.component';

import { DataService } from './data/data.service';
import { UserSession } from './data/userSession.class';

@Component({
    selector: 'my-catalog-backend', 
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss'],
})
export class AppComponent {
    @ViewChild(DialogComponent) dialog: DialogComponent;

    constructor(private dataService: DataService, private router: Router) {
    }

    ngOnInit() {
     
        this.dataService.getUserSession().subscribe(
            (userSession: UserSession) => {
                if (userSession) {
                    this.router.navigate(['products' /*,1*/ ]);
                } else {
                    this.router.navigate(['login']);
                }
            });
    }
}

@Foxandxss
Copy link
Member

Super hard to read. Clean it up please, remove comments and stuff.

@arthur-melo
Copy link

I think I've found it, you have imported OnInit interface declaration and also implemented its method, but your class does not use that interface. To fix it, just update your export class AppComponent to export class AppComponent implements OnInit and check if the error goes away.

Docs: https://www.typescriptlang.org/docs/handbook/interfaces.html

@phil123456
Copy link
Author

phil123456 commented Mar 31, 2017

ok so apparently it gets triggered, but the ts files are not debugable
even if I set breakpoints they are never reached
I'll create a new thread for this, since it's a different issue

@warapitiya
Copy link

warapitiya commented Apr 12, 2017

@phil123456 that's the normal behaviour of webpack. It's nothing to do with the angular-webpack stater kit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants