1.Hello。我从array
json
向this.contentArray
view
发送*ngFor
length
array
个console.log(this.contentArray.length); // is 2
。 div
的{{1}}为:html
,因此从逻辑上讲,它必须显示2 divs
个已加载的数据。
但是在divs
页面中显示3 <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>
,最后一个是空的,没有数据。
它能是什么?我只能查看2 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
}
}
我的数据?
它还显示问题标题中显示的错误。
2.homePageTemplate.html
Aspect Ratio
3.Home.ts
$(document).ready(function(){
$(".ez-checkbox").click(function() {
console.log("ok");
var re = {Brand: "", Cost: "", OS: ""};
$("#Brand :checkbox:checked").each(function(){
re.Brand += $(this).val()+" & ";
});
$("#Cost :checkbox:checked").each(function(){
re.Cost += $(this).val()+" & ";
});
$("#OS :checkbox:checked").each(function(){
re.OS += $(this).val()+" & ";
});
if(re.lenght==0){
}
else{
$.ajax({
method: "POST",
dataType: "json", //type of data
crossDomain: true,
data: re,
url:"./php/filtered-device-query.php",
success: function(response) {
//display the filtered devices
},
error: function(request,error)
{
console.log(request+":"+error);
}
});
}
});
});
4.提前谢谢你。)
答案 0 :(得分:1)
我发现了我的问题,第3个空div。 如您所见,我对同一元素有两个指令:
<div class="row" *ngIf="showAssigned" *ngFor="let item of contentArray">
因此,nrFor用我的数据创建2 div,而ngIf创建一个没有数据的元素。这很好用:
<div *ngIf="showAssigned">
<div class="row" *ngFor="let item of contentArray"></div>
</div>