我有角度2客户端 在component.ts上我创建了一个ngOnInit
ngOnInit(){
var grid = document.getElementById('devpro');
grid.addEventListener('selected-items-changed', function() {
var selected = grid.selection.selected();
if (selected.length == 1) {
this.detailproject = [];
var prodetails = grid.items[grid.selection.selected()].ProjectName;
console.log(prodetails);
this.getdetailsproject(prodetails); <<<<<< this part
var detailsproject :any = document.getElementById('detailsproject');
if (detailsproject) {
detailsproject.open();
}
}
});
}
getdetailsproject(prodetails){ <<< this is my function
this._httpprovider.httpReq('http://localhost:5000/getdetailsproject','POST',{ProjectName:prodetails},null).subscribe((data)=>{
var dprodetails = [];
for (let i=0;i<data.length;i++){
dprodetails.push(data[i]);
}
this.detailproject = dprodetails;
});
}
我试着在里面调用它并没有任何结果它只是一个错误说我的getdetailsproject不是一个函数
有没有办法按正常方式调用它?
答案 0 :(得分:5)
在类型脚本中使用
grid.addEventListener('selected-items-changed', () => { })
而不是
grid.addEventListener('selected-items-changed', function() { });
答案 1 :(得分:0)
您的代码是正确的。但问题是js的功能。如果你正在放置console.log(prodetails);在你的功能中,它将像魅力一样工作。您将其置于函数旁边,因此js会在执行getdetailsproject()函数之前自动调用控制台。使用此
getdetailsproject(prodetails){ <<< this is my function
this._httpprovider.httpReq('http://localhost:5000/getdetailsproject','POST',{ProjectName:prodetails},null).subscribe((data)=>{
var dprodetails = [];
for (let i=0;i<data.length;i++){
dprodetails.push(data[i]);
}
this.detailproject = dprodetails;
console.log(this.detailproject);
});
}
&#13;
然后你可以创建另一个函数来调用其余的功能。注意:Javascript / typescript不能一步一步地工作。它不会等待任何响应延迟