受信したデータを3つの入力に入れたいと思います。私はノードサーバーからjson応答を受け取り、コントローラーは応答を受け取って3つの入力に配置する必要があります。 は私が応答を受信しますが、私は入力に配置することはできません入力に応答を配置する方法angularjs
コントローラー:
$scope.edit = function(id, contact) {
console.log(id);
$http.get('/contactlist/' + id).then(function(response) {
console.log(response);
$scope.contact = response;
});
};
サーバー:
app.get('/contactlist/:id', function (req, res) {
var id = req.params.id;
console.log(id);
connection.query('SELECT * FROM contactlist WHERE id = ' + id, function (error, results, fields) {
console.log(results);
res.json(results);
});
});
のindex.html:
<div class="input-field col s4">
<input id="name" type="text" class="form" ng-model="contact.name">
<label for="name">Nom</label>
{{contact.name}}
</div>
<div class="input-field col s4">
<input id="email" type="text" class="form" ng-model="contact.email">
<label for="email">Email</label>
</div>
<div class="input-field col s4">
<input id="number" type="text" class="form" ng-model="contact.number">
<label for="number">Numéro</label>
</div>
応答はクロームで受信された: response from chrome object
では? –
'response'はあなたがログに記録するときのように見えますか?おそらく '$ scope.contact = response.data'であるべきです。 – tymeJV
$ scope.contact = responseを変更してください。 〜$ scope.contact = response.data; – Vivz