我正在关注Angular JS上的Udemy教程并面对这个问题。
我的app.component.ts代码
import {Component} from 'angular2/core';
import {CoursesComponent} from './courses.component'
import {AuthorComponent} from './author.component'
import {FavouriteComponent} from './favourite.component'
@Component({
selector: 'my-app',
template: `
<h1>Hello Kuttu</h1><courses></courses><authors></authors>
<fav></fav>
`,
directives: [CoursesComponent,AuthorComponent,FavouriteComponent]
})
export class AppComponent {
}
我最喜欢的组件代码
import {Component} from 'angular2/core'
@Component({
selector: 'fav',
template: `
<i
class="glyphicon"
[class.glyphicon-star-empty]="!isFavourite"
[class.glyphicon-star]="isFlag"
(click)="onBClick()"
>
</i>
`
})
export class FavouriteComponent(){
isFavourite = false;
onBClick(){
this.isFavourite = !this.isFavourite;
}
}
星星在视图中呈现,当我点击时,我得到了异常
EXCEPTION: Error during evaluation of "click"
angular2.dev.js:23083 EXCEPTION: Error during evaluation of "click"
BrowserDomAdapter.logError @ angular2.dev.js:23083
BrowserDomAdapter.logGroup @ angular2.dev.js:23094
答案 0 :(得分:0)
犯了一个愚蠢的错误
FavouriteComponent(){
在类名中有一个(),因为我的编辑器不能编译,我错过了这个错误。