2017-04-25 5 views
0

각도 응용 프로그램을 가지고 있는데,이 응용 프로그램을 개발 환경 (npm run build)으로 빌드하면 완전히 작동합니다.생산을위한 각도 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

템플릿에서 직접 '라우터'에 액세스하십니까? – jonrsharpe

+0

예 .. 템플릿에 직접 라우터를 사용하고 있습니다. app.component.html – undefined

답변

0

제작 빌드가 더 엄격하므로 범위 밖에서 개인 개체에 액세스 할 수 없습니다. app.component.html은 라우터에 직접 액세스 할 수 없습니다. 앱 구성 요소에 공용 함수를 작성하고 내부에서 개인 라우터를 호출 할 수 있습니다.

+0

문제가 생겨서 죄송합니다. 어떻게 달성 할 수 있는지 보여 주시겠습니까? 새로운 각도 2입니다. – undefined

+0

원하는 작업에 따라 다릅니다. 구성 요소에는 onButtonClicked() {this.router.navigate ("location");}를 사용할 수 있습니다. 그런 다음 템플릿에 (클릭) = "onButtonClicked()"버튼이 있습니다. –

+0

감사합니다. – undefined

관련 문제