我通过我在app.component.html
的app组件中声明的代码获取当前的urlapp.component.ts
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
public href: string = "";
constructor(private router: Router) {}
ngOnInit() {
}
}
app.component.html
<div class="page-wrap {{router.url}}">
<app-header></app-header>
<div class="content-wrap">
<app-sidebar></app-sidebar>
<div class="app-content">
<flash-messages></flash-messages>
<router-outlet></router-outlet>
</div>
</div>
</div>
当我通过&#34; ng serve -prod&#34;编译上面的代码时,系统会提示我:
C:/ Users / theone / Documents / Node Projects中的错误 SourceTree /梦角/ src目录/ $$ _ gendir /应用/ app.component.ngfactory.ts (58,68):物业&#39;路由器&#39;是私人的,只能在课堂上访问 &#39; AppComponent&#39;
答案 0 :(得分:1)
错误消息告诉您确切的错误。这个领域是私人的。无法从模板访问它。试试
constructor(public router: Router) { }
答案 1 :(得分:0)
尝试使用
ng build --env=prod
Seems ng build --env=prod and ng build --prod are not same.
如果您使用的是旧版本,则会出现angular-cli的已知问题。或者您需要将其更改为公开
constructor(public router: Router) { }
以下是上述问题:Scannes#hasNextInt