我有角度2 rc1 http get方法的问题:
提供的参数与呼叫目标的任何签名都不匹配。
export class BaMsgCenter {
public messages;
public data_error: Boolean = false;
constructor(private _baMsgCenterService:BaMsgCenterService) {
this.messages = this._baMsgCenterService.getMessages().subscribe(
(messages: Array<any>) => {
debugger;
let result:Array<Message> = [];
if (messages) {
messages.forEach((message) => {
result.push(
new Message(message[0],
message[1],
message[2],
message[3],
message[4])
);
});
}
return messages;
},
err => { this.data_error = true}
);
}
}
然后:
export class Message {
id: number;
message: string;
send_date: string;
status: number;
from: string;
}
消息类:
new Message(message[0], (...)
错误符合:[[1,"Title",1468669921000,0,"Siva"],[2,"Title",1468669934000,0,"Siva2"]]
。
可能这与承诺有关,但我不知道如何解决它。
我想将json数组解析为object,如:
{{1}}
有些想法?
谢谢!
答案 0 :(得分:1)
您的Message
类没有构造函数。你应该写:
export class Message {
constructor(public id: number,
public message: string,
public send_date: string,
public status: number,
public from: string) {}
}