admin 管理员组文章数量: 1086019
I'm having an issue when I start my angular app.
I have a function that does a post request, returns some data to my ponent and plots a chart. It works fine after I start the app do some random modification and save, but when I first start the app I get Property 'length' does not exist on type 'Object'.
on a for loop I have on my response array.
I've tried iterating through the response, only if it's not null, but that didn't work.
function:
dailyForecast() {
var token = {token : "0a1b2c3d"};
return this._http.post("", token)
.map(result => result);
}
I get the error inside this for loop, but it works fine after I re-pile.
ngOnInit() {
let chart = < any > {};
this._weather.dailyForecast()
.subscribe(res => {
console.log(res);
let browsers = [];
let browsersAcesss = [];
if (res !== null) {
for (var i = 0; i < res.length; i++) {
browsers.push(res[i][0]);
browsersAcesss.push(res[i][1]);
}
}
});
}
I'm having an issue when I start my angular app.
I have a function that does a post request, returns some data to my ponent and plots a chart. It works fine after I start the app do some random modification and save, but when I first start the app I get Property 'length' does not exist on type 'Object'.
on a for loop I have on my response array.
I've tried iterating through the response, only if it's not null, but that didn't work.
function:
dailyForecast() {
var token = {token : "0a1b2c3d"};
return this._http.post("https://www.improving..br/api/test/hits-by-browser", token)
.map(result => result);
}
I get the error inside this for loop, but it works fine after I re-pile.
ngOnInit() {
let chart = < any > {};
this._weather.dailyForecast()
.subscribe(res => {
console.log(res);
let browsers = [];
let browsersAcesss = [];
if (res !== null) {
for (var i = 0; i < res.length; i++) {
browsers.push(res[i][0]);
browsersAcesss.push(res[i][1]);
}
}
});
}
Share
Improve this question
edited Oct 16, 2018 at 14:08
user5734311
asked Oct 16, 2018 at 14:01
queroga_vqzqueroga_vqz
1,0493 gold badges12 silver badges29 bronze badges
6
- 1 Absolutely nothing here? google.nl/… – mplungjan Commented Oct 16, 2018 at 14:03
- Have not found a thread where this problem only happens on initial build. – queroga_vqz Commented Oct 16, 2018 at 14:05
- What does the data look like when it errors out? Is it changing? Check your network tab in dev tools. – Frank Modica Commented Oct 16, 2018 at 14:08
-
what does
console.log(res);
return as the error occur – Hana Wujira Commented Oct 16, 2018 at 14:10 - @FrankModica dev network tab shows a generic t=1539699003903 net::ERR_CONNECTION_REFUSED – queroga_vqz Commented Oct 16, 2018 at 14:13
1 Answer
Reset to default 8If you want to avoid the pile error you can set the response type to any[]
or a custom interface.
ngOnInit() {
let chart = < any > {};
this._weather.dailyForecast()
.subscribe((res: any[]) => {
console.log(res);
let browsers = [];
let browsersAcesss = [];
if (res !== null) {
for (var i = 0; i < res.length; i++) {
browsers.push(res[i][0]);
browsersAcesss.push(res[i][1]);
}
}
});
}
本文标签:
版权声明:本文标题:javascript - TS2334 Property 'length' does not exist on type 'Object'. on app start only (ng-ser 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744065832a2527575.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论