angular - Angular 5:不使用 ngFor 属性进行渲染
问题描述
我在使用*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 有什么特别之处吗?
解决方案
JB尼泽:
item.Any must be an empty string, or null, or undefined.
推荐阅读
- laravel - Laravel nova - 基于另一个字段的自定义字段设置值并且仍然可以编辑
- alexa - 如果我使用自己的端点,如何将 ask-sdk 与节点 js 一起使用?
- r - 一张图表中的多个水平条形图
- python - 是否可以让客户端与服务器端的 recaptcha 交互?
- apache - 如何以类似 MVC 的方法将 URL 重写为 index.php
- amazon-web-services - 无法创建 ScalingPolicy - 未注册可扩展目标
- here-api - HereMaps语音指导中TBT信息的触发点
- sql - 仅借用指定作者和编辑的所有书籍的借款人
- vue.js - VueJS - 从数据中自动创建一个 AZ 字母列表
- php - 显示总计为 0