Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法运行angular cli命令来生成产品_Angular_Angular Cli - Fatal编程技术网

无法运行angular cli命令来生成产品

无法运行angular cli命令来生成产品,angular,angular-cli,Angular,Angular Cli,我有一个Angular应用程序,当我在开发环境中构建这个应用程序时(npm run build),它运行得非常好 但当我尝试使用生产标签构建时,它失败了,出现以下错误: C:/Users/1234/app/src/$$\u gendir/app/app.component.ngfactory.ts (617,85):财产“路由器”是私有的,只能在 类“AppComponent” 我知道路由器是私有的(在下面的代码中),但它如何在开发实例中正常工作,并且只有AppComponent.html才能使

我有一个Angular应用程序,当我在开发环境中构建这个应用程序时(
npm run build
),它运行得非常好

但当我尝试使用生产标签构建时,它失败了,出现以下错误:

C:/Users/1234/app/src/$$\u gendir/app/app.component.ngfactory.ts (617,85):财产“路由器”是私有的,只能在 类“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
    }
}

生产构建更为严格,因此不允许访问范围外的私有对象。您的app.component.html将无法直接访问路由器。您可以在应用程序组件中编写一个公共函数,并从内部调用专用路由器。

此处报告的类似问题:您是否直接在模板中访问路由器?。。我正在使用路由器直接进入模板app.component.htmlSorry麻烦了。但是你能告诉我如何实现这一点吗。我是Angular2新手。这取决于你想做什么。在组件中,可以有onButtonClick(){this.router.navigate(“location”);}。然后,您的模板中有一个按钮(单击)=“onButtonClicked()”没问题:)享受