我遇到 * ngFor 的问题。我的长度还可以,但是数据无法渲染。
我正在使用 Angular 5 和Typescript。
我的组件是:
@Component({
selector: 'app-reglada',
templateUrl: './reglada.component.html',
styleUrls: ['./reglada.component.css'],
providers: [DataService]
})
export class RegladaComponent implements OnInit {
public reglada: Reglada[] = new Array<Reglada>();
public console = console;
constructor(public data: DataService, globals: Globals)
{
data.cargarDades(new Reglada()).then(
res => { // Success
var items = JSON.parse(JSON.stringify(res));
for (var i = 0; i < items.length; i++) {
var obj = Object.assign({}, items[i]); //copy data from webapi... result is ok
this.reglada.push(obj); // push in the public variable. obj data is working ok.
}
}
);
}
ngOnInit() {
}
}
我的poco是:
export class Reglada extends Base {
public Cultura: string;
public Any: number;
public Descripcio: string;
public Academia: string;
}
我的html是:
--{{reglada.length}}-- HERE I AM GETTING rows and it is ok
<P *ngFor="let item of reglada"> <!-- HERE MAKES THE LOOP but item.Any is not displayed. -->
<label class="negreta">{{item.Any}}.</label> {{item.Descripcio}}. {{item.Academia}}.
</P>
我的模块是:
const routes: Routes = [{
path: '',
data: {
title: 'Curriculum Vitae',
urls: [{ title: 'Detall', url: '/cv' }, { title: 'CV' }]
},
component: CVComponent
}];
@NgModule({
imports: [
FormsModule,
CommonModule,
HttpClientModule,
RouterModule.forChild(routes),
TagsInputModule.forRoot()
],
declarations: [
CVComponent,
ClientComponent,
CapcaleraComponent,
EducacioComponent,
ExperienciaLaboralComponent,
RegladaComponent,
NoRegladaComponent,
IdiomesComponent,
EducacioComponent,
ConeixementsComponent
]
})
export class CVModule { }
发生了什么事? Angular 5有什么特别之处吗?
答案 0 :(得分:0)
JB Nizet:
item.Any must be an empty string, or null, or undefined.