2017-09-18 1 views
0

버튼을 한 번 클릭하여 기능을 실행하려고합니다. 아래로 내 현재 코드이지만 작동하지 않습니다. 이것은 내 app.component가 아니며 두 번째 탭에서이 작업을 수행하려고합니다.버튼을 클릭 한 각도 CLI 기능

추가 profile.component.html

<button ng-click="myFunc()">Click</button> 

추가 profile.components.ts

export class AddProfileComponent implements OnInit { 

    constructor() { 
    this.showWindow(); 
    } 

    myFunc():void{ 
    console.log("Works"); 
    } 

    ngOnInit() { 

    } 
} 

답변

1

당신이 각 2를 사용하는 경우, 당신은 ng-click을 사용할 수 없습니다. (click)

또한
<button (click)="myFunc()">Click</button> 

사용

export class AddProfileComponent implements OnInit { 

    constructor() { 
    this.showWindow(); 
    } 
    showWindow(){ 
    // your code 
    } 
    myFunc():void{ 
    console.log("Works"); 
    } 

    ngOnInit() { 

    } 
} 
+0

덕분에이 근무 showWindow 기능을 구현! 이것은 기존의 모든 ng 명령에 영향을 줍니까? 또는 단지 이것 (Angular 2를 사용할 때 (나는 각진 CLI를 사용하고있다)). – Amar

+0

각도 2는 각도 1 구현과 다릅니다. 문서를 제대로 읽어야합니다. 그리고 네, 그 다른 –