2017-04-25 59 views
0

我有一个Angular应用程序,当我在开发环境(npm run build)中构建此应用程序时,它工作得很好。无法运行angular-cli命令来构建生产

但是当我尝试建立与生产标签时,出现此错误:

C:/Users/1234/app/src/$$_gendir/app/app.component.ngfactory.ts (617,85): Property 'router' is private and only accessible within 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

在此处报告了类似问题:https://github.com/angular/angular/issues/15451 – undefined

+0

您是否直接在模板中访问'router'? – jonrsharpe

+0

是的..我使用路由器直接进入模板app.component.html – undefined

回答

0

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

+0

对不起,麻烦..但你可以请示范如何实现这一点..我是新的angular2 – undefined

+0

这取决于你想做什么。 在你的组件中,你可以有onButtonClicked(){this.router.navigate(“location”);}。然后你的模板中有一个按钮(点击)=“onButtonClicked()” –

+0

我明白了。谢谢 – undefined