我有一个Angular应用程序,当我在开发环境(npm run build
)中构建此应用程序时,它完全正常。
但是当我尝试使用生产标签进行构建时,它会因此错误而失败:
C:/用户/ 1234 /应用程序/ SRC / $$ _ gendir /应用/ app.component.ngfactory.ts (617,85):属性“路由器”是私有的,只能在其中访问 class'AppComponent'。
我知道路由器是私有的(在下面的代码中),但它如何适用于开发实例,除了AppComponent.html之外没有其他人能够使用它?
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(private router: Router, private _cookieService:CookieService) {
//some function
}
}
答案 0 :(得分:0)
生产构建更严格,因此不允许您访问范围之外的私有对象。您的app.component.html将无法直接访问路由器。您可以在应用程序组件中编写公共函数,并从内部调用专用路由器。