Arrayオブジェクトを$http.get()
に渡したいと思います。以前はすべての情報がdata.json
ファイルに保存されていましたが、ファイルを使用したくありません。コントローラのオブジェクトの配列を$scope.data
として定義します。 我々はdata.jsonを使用しているDEMO http://plnkr.co/edit/X5ZC3UGey4Zjos7W01U1?p=preview
ワーキングDEMO http://plnkr.co/edit/o6EeKnC8oFEq3GCRsQgp?p=preview こちらをご覧ください。私は、コントローラにdata.json内のデータを定義したい、Plzを私はこれを使用していますか
.controller('QuestionCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.questions = [];
$scope.data = {
"questions": [
{
"question": "Qw1",
"answers": [
{
"answers": "An1",
"value": 25
},
{
"answers": "An2",
"value": 50
},
{
"answers": "An3",
"value": 75
},
{
"answers": "An4",
"value": 100
}
]
},
{
"question": "Qw2",
"answers": [
{
"answers": "An1",
"value": 25
},
{
"answers": "An2",
"value": 50
},
{
"answers": "An3",
"value": 75
},
{
"answers": "An4",
"value": 100
}
]
}
]
}
$http
.get(JSON.stringify($scope.data))
.then(function(response){
$scope.questions = response.data.questions;
});
}])
私は質問をしません。あなたは何を達成しようとしていますか? $ httpでjsonを取得しますか? –
@Poyrazここでは、data.jsonを使用していますかどうかを確認してください。plnkr.co/edit/o6EeKnC8oFEq3GCRsQgp?p=preview私はController内のdata.json内のデータを定義したい、Plzはあなたのjsonデータと$ HTTPを1つのコントローラで – Guest
として実行し、$ httpを使用する必要はありません。 –