I have an Angular app, when I build this app in development environment (npm run build) it works completely fine.
But when I try to build with production tag, it fails with this error:
C:/Users/1234/app/src/$$_gendir/app/app.component.ngfactory.ts (617,85): Property 'router' is private and only accessible within class 'AppComponent'.
I know router is private (in below code), but how is it working fine for development instance, and none but AppComponent.html should be able to use that?
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(private router: Router, private _cookieService:CookieService) {
//some function
}
}
Production build is stricter and thus doesn't let you access private objects outside of scope. You app.component.html will not be able to access router directly. You could write a public function in your app component and call the private router from within.