2016-10-23 4 views
0

私は現在、user-service.tsファイルでIonic 2プログラムを呼び出してユーザーフィールドを更新しようとしています。次のコードがあります。Ionic 2 Expressコールがユーザー更新機能に応答していない

私はserver.jsファイルには、以下を実行する必要があり、これを呼び出す
 // Update a user 
update(user: User): Observable<User> { 
let url = `${this.usersUrl}/${user._id}`; 
let body = JSON.stringify(user); 
let headers = new Headers({'Content-Type': 'application/json'}); 
console.log(url, body); 
return this.http.put(url, body, {headers: headers}) 
       .map(() => user) //See mdn.io/arrowfunctions 
       .catch(this.handleError); 
} 

// PUT: update a todo by id 
app.put("/api/users/:id", function(req, res) { 
console.log('test'); 
var updateUser = req.body; 
delete updateUser._id; 

db.collection("users").updateOne({_id: new ObjectID(req.params.id)}, updateUser, function(err, doc) { 
if (err) { 
    handleError(res, err.message, "Failed to update user"); 
} else { 
    res.status(204).end(); 
} 
}); 
}); 

ユーザーservice.tsファイルの私はconsole.logコピー&ペーストするときには、正しく機能を呼び出し、テストメッセージを表示しますしかし、これは単独では機能しません。どんな提案も大歓迎です。ありがとう

答えて

0

あなたのupdateコールに何かを購読する必要があるようです。例えば

userService.update(myUser).subscribe((response:any) => { 
    //Do something with the response. 
}); 
+0

これがまさに問題です。本当にありがとう! – Darth123

関連する問題