1.Hello.I send an array
from json
file to this.contentArray
for view
it in *ngFor
. the length
of array
is: console.log(this.contentArray.length); // is 2
, so logically it has to show 2 div
with loaded data.
but in html
page shows 3 divs
,and the last one is empty,without data.
What can it be? ho to view only 2 divs
with my data?
Also it shows error shown in question title.
2.homePageTemplate.html
<div class="container">
<div class="row">
<div class="row" *ngIf="showAssigned" *ngFor="let item of contentArray">
<div class="row assignedItem col-sm-offset-1">
<span class="glyphicon glyphicon-plus-sign " title="sub items"></span>
<div class=" itemName" title="State:{{item.state}},Type: {{item.type}}">{{item.name}}</div>
<span class="glyphicon glyphicon-user" title="view assigned users"></span>
<span class="glyphicon glyphicon-paperclip" title="attached docs"></span>
</div>
</div>
</div>
</div>
3.Home.ts
import {Component} from '@angular/core';
import {StructureRequestService} from './StructureRequestService';
import {Observable} from 'rxjs/Observable';
export class Content {
ok: boolean;
content: Array;
}
@Component({
providers: [StructureRequestService],
styleUrls: ['app/home/home.css'],
templateUrl:'./app/home/homePageTemplate.html'
})
export class HomeComponent {
contentArray = [];
myRes: Content;
showAssigned:boolean = false;
constructor(private structureRequest: StructureRequestService) {}
ngOnInit() {
this.structureRequest.sendRequest();
}
viewNodes() {
this.myRes = this.structureRequest.result;
this.contentArray = this.myRes.content;
this.showAssigned = true;
console.log(this.contentArray.length); // is 2
}
}
4.thank you in advance:)