我有2個json文件,services.json和services_show.json.At頁面加載正在從services.json獲取數據,它正常工作。在按鈕單擊時,我需要獲取內容從service_show.json並附加到服務數組,但它不起作用。將json數據添加到現有陣列
var beautyApp = angular.module('findbeauty', []);
beautyApp.controller('beautycntrl',function($scope,$http){
$http.get('http://localhost/Find-Beauty/media/services.json').success(function(data) {
$scope.services=data.services;
$scope.services1=data.services1;
});
$scope.Add = function(){
$http.get('http://localhost/Find-Beauty/media/services_show.json').success(function(data) {
console.log(angular.toJson(data.services));
$scope.services.push(data.services);
});
};
$scope.ViewMore = function(){
});
Services.json
{
"services":[
{
"name": "Arun",
"gender": "Damen",
"duration": "1.5 Stunden",
"price": "€65,00",
"imagepath": "media/images/prfilepic1.png",
"percentage": "90%"
},
],
"services1":[
{
"name": "Schnitt & Föhnen",
"gender": "Damen",
"duration": "1.5 Stunden",
"price": "€65,00",
"imagepath": "media/images/profilepic4.png",
"percentage": "25%"
},
]
}
service_show.json
{
"services":[
{
"name": "Schnitt & Föhnen",
"gender": "Damen",
"duration": "1.5 Stunden",
"price": "€65,00",
"imagepath": "media/images/profilepic4.png",
"percentage": "5%"
},
],
"services1":[
{
"name": "Schnitt & Föhnen",
"gender": "Damen",
"duration": "1.5 Stunden",
"price": "€65,00",
"imagepath": "media/images/prfilepic1.png",
"percentage": "50%"
},
]
}
我怎麼能在services_show.json數據推至$ scope.services?任何幫助?
你的意思是什麼不起作用?你錯過了關閉你的控制器,這樣代碼無論如何都不會工作。在這裏找到正確的代碼:https://gist.github.com/VictorBjelkholm/8b2004289ed9b4336034 –
試過在本地運行你的代碼,它對我來說工作正常.. – user700284
感謝所有的答覆.. – Gopesh