require 'json'
class A
attr_accessor :a, :b, :c
def initialize(a, b, c)
@a = a, @b = b, @c = c
end
end
a = A.new(1, "a", [1, 2, 3])
p a
puts "\n\nJSON: "
puts a.to_json
puts "\n\nJSON.pretty_generate: "
puts JSON.pretty_generate(a)
我正在尝试使用Ionic2和Angular2 beta创建移动应用程序。此应用程序将使用POST向Rails Web服务发送电子邮件。 Rails Web服务工作得很好。我似乎没有开始使用移动应用程序。
答案 0 :(得分:1)
存在误解
this.send(subject, body).subscribe(res => {
console.log(message);
console.log(this._apiUrl);
});
将采用不同的方法
onSubmit(value) {
this.send(value.subject, value.body)
.subscribe(res => {
console.log(message);
console.log(this._apiUrl);
});
}
send(subject, body)
{
var message = "subject=" + subject + "&body=" + body;
return this.http.post(this._apiUrl,
body,
{
headers: this.headers
}).map(res => {
this.comments = res.json();
});
}
答案 1 :(得分:1)
您应该以这种方式重构代码:
onSubmit(value) {
this.send(value.subject, value.body).subscribe(res => {
console.log(message);
console.log(this._apiUrl);
});
}
send(subject, body)
{
var message = "subject=" + subject + "&body=" + body;
let result = this.http.post(this._apiUrl,
body,
{
headers: this.headers
}).map(res => {
this.comments = res.json();
});
return result;
}