I've spent quite alot of time going over AngularJS these past few days, it's starting to all click now :) but the one question i can't seem to answer is how i get my factory to return the data as JSON - not as a promise OR even if i should!
There are a few reasons i can't see the result, A) the promise is incomplete, B) I shouldn't be doing it this way and should actually just stick with the 'then()' in the controller. Ideally i want to write one line in the controller but i always get an undefined unless i follow the pattern in the example.
Am i going against the grain on this where i don't need to?
// Will go into application.js
(function () {
var app = angular.module("ngOrderApp", []);
}());
// Will go into orderFactory.js
(function () {
var order = function ($http) {
var getOrdersJson = function () {
return [{ OrderId: 101 }, { OrderId: 102 }, { OrderId: 103 }];
}
var getOrdershttp = function () {
return $http.get('api/order')
.success(function (result) {
return result.data;
});
}
return {
getOrdersJson: getOrdersJson,
getOrdershttp: getOrdershttp
};
}
var app = angular.module("ngOrderApp").factory("order", order);
}());
// Will go into orderController.js
(function () {
var app = angular.module("ngOrderApp").controller('OrderController', function ($scope, order) {
$scope.jsonorders = order.getOrdersJson();
order.getOrdershttp().then(function (result) {
$scope.httporders = result.data;
});
});
}());