我是AngularJs 2的新手我正在尝试NgFor工作,但我有这个错误,我无法弄清楚出了什么问题:
skills.template.html
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="skills-container">
<div *ngFor="let item of [0,1,3,4,5];">Try</div>
</div>
</div>
skills.compontent.ts
import { Component } from '@angular/core';
import { OnInit } from '@angular/core';
import {Candidate} from "../../../../models/Candidate";
import {Input} from '@angular/core';
import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'skills',
templateUrl: 'skills.template.html',
providers:[NgbModal]
})
export class skillsComponent implements OnInit {
@Input() selectedCandidate:Candidate;
constructor(private modalService:NgbModal){ }
ngOnInit(){}
launchSkillsModal(e:any, content:any){
const modalRef = this.modalService.open(content);
e.preventDefault();
}
}
我只是尝试一个简单的循环,但我得到了
main.bundle.js:6017Error: Template parse errors:(…)(anonymous function) @ main.bundle.js:6017ZoneDelegate.invoke @ zone.js:232Zone.run @ zone.js:114(anonymous function) @ zone.js:502ZoneDelegate.invokeTask @ zone.js:265Zone.runTask @ zone.js:154drainMicroTaskQueue @ zone.js:401
答案 0 :(得分:0)
似乎您正在使用older
Angular 2版本,因为组件元数据中的providers
已被弃用。在您的情况下,它可以使用较旧的语法#item
而不是let item
。
*ngFor="#item of [0,1,3,4,5];"
虽然我强烈建议您将角度版本更新到最新版本(2.4.1)