我有一個web項目和使用角2我用不同的頁面使用單擊事件沒有任何問題,但創建新頁面然後單擊事件在新頁面中出現錯誤。Angular 2單擊事件不起作用
此錯誤
TypeError: self.parentView.parentView.context.changedItem is not a function at View_SiteConfig3.handleEvent_0 (/AppModule/SiteConfig/component.ngfactory.js:137) at View_SiteConfig3.eval (core.umd.js:12399) at HTMLTextAreaElement.eval (platform-browser.umd.js:3223) at ZoneDelegate.invokeTask (zone.js:265) at Object.onInvokeTask (core.umd.js:3971) at ZoneDelegate.invokeTask (zone.js:264) at Zone.runTask (zone.js:154) at HTMLTextAreaElement.ZoneTask.invoke (zone.js:335)
站點config.html
<div *ngFor="let item of items1; let i = index;" class="col-sm-4">
<button (click)="changedItem(item)">Test</button>
</div>
站點config.ts
import { Component, OnInit } from '@angular/core'
import { Http } from '@angular/http'
@Component({
selector: 'site-config',
moduleId: module.id,
templateUrl: '/site-config.html'
})
export class SiteConfig implements OnInit {
items1: number[] = [1,2,3]
ngOnInit(): void {
}
public changedItem(item) {
//My Codes This Here
}
constructor(private http: Http) {
}
}
編輯:解決了這個方法的問題;
My project worked. Problem is ts file not compiled then give a "is not a function" error
你能否發佈changedItem方法? –
唯一changedItem方法不起作用,我的所有代碼上面沒有app.ts文件 –