- 我是 Angular 新手,我尝试在单击每个 li 时更改它的颜色。
- 但我收到错误 VM1052:19 错误:(SystemJS) TypeScript 转译失败
- 你们能告诉我如何解决这个问题吗?
- 提供下面的代码
http://plnkr.co/edit/npNw39aRZVgpqEjI6uLH?open=app%2Fapp.component.ts&p=preview
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
styles: [`
li {
color: red;
}
`],
template: `<ul class= "master">
<li *ngFor ="let student of liArraycontent" (click) = "liClicked($event)"> {{student}} </li>
</ul>`
})
export class AppComponent {
name = 'Angular';
liArraycontent = ["testing 1", "testing 2", "testing3"]
liClicked = function(e1) {
console.log(e1.target);
e1.addCss(color: green);
}
}
最佳答案
您只需要添加样式属性即可。
在点击事件中添加这一行:
e1.target.setAttribute("style", "color: green;");
链接到工作plnkr: http://plnkr.co/edit/w1i9v1fJ02htbDrtkWUy?open=app%2Fapp.component.ts&p=preview
关于javascript - VM1052 :19 Error: (SystemJS) TypeScript transpilation failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44425782/