Ok here we go. I have an angularjs platform and I want to call the data in my controllers scope from an external php files. This is the original code.
.controller("morrisChartCtrl", ["$scope",
function ($scope) {
return $scope.mainData = [{
month: "2013-01",
xbox: 294e3,
will: 136e3,
playstation: 244e3
}, {
month: "2013-02",
xbox: 228e3,
will: 335e3,
playstation: 127e3
}, {
month: "2013-03",
xbox: 199e3,
will: 159e3,
playstation: 13e4
}, {
month: "2013-04",
xbox: 174e3,
will: 16e4,
playstation: 82e3
}, {
month: "2013-05",
xbox: 255e3,
will: 318e3,
playstation: 82e3
}, {
month: "2013-06",
xbox: 298400,
will: 401800,
playstation: 98600
}, {
month: "2013-07",
xbox: 37e4,
will: 225e3,
playstation: 159e3
}, {
month: "2013-08",
xbox: 376700,
will: 303600,
playstation: 13e4
}, {
month: "2013-09",
xbox: 527800,
will: 301e3,
playstation: 119400
}], $scope.simpleData = [{
year: "2008",
value: 20
}, {
year: "2009",
value: 10
}, {
year: "2010",
value: 5
}, {
year: "2011",
value: 5
}, {
year: "2012",
value: 20
}, {
year: "2013",
value: 19
}], $scope.comboData = [{
year: "2008",
a: 20,
b: 16,
c: 12
}, {
year: "2009",
a: 10,
b: 22,
c: 30
}, {
year: "2010",
a: 5,
b: 14,
c: 20
}, {
year: "2011",
a: 5,
b: 12,
c: 19
}, {
year: "2012",
a: 20,
b: 19,
c: 13
}, {
year: "2013",
a: 28,
b: 22,
c: 20
}], $scope.donutData = [{
label: "Download Sales",
value: 12
}, {
label: "In-Store Sales",
value: 30
}, {
label: "Mail-Order Sales",
value: 20
}, {
label: "Online Sales",
value: 19
}]
}
])
Instead of inline data in the js file I want to use $http
to get the code for each scope from a individual php file that will generate to JSON format.
What is wrong with this format
.controller("morrisChartCtrl", ["$scope",
function ($scope) {
return $scope.mainData = $http.get('php/mainData.php').success(function (data) {
$scope.mainData = data;
}), $scope.simpleData = $http.get('php/simpleData.php').success(function (data) {
$scope.simpleData = data;
}), $scope.comboData = $http.get('php/comboData.php').success(function (data) {
$scope.comboData = data;
}), $scope.donutData = $http.get('php/donutData.php').success(function (data) {
$scope.donutData = data;
})
}
])
Just trying to figure out the right structure
$http
, read the docs , go through the docs tutorial code that shows examples...do some research in other words. – charlietfl Jul 20 '14 at 20:20