Trying to set up Angular factory/service to consume API data, so I can build default index and show pages.
My problem is that data not returned from factory to controller and view.
My second issue is when I click on customer it should query API again and return concerned customer. However I'm mixed up on how to pass customerID
through routeParams
app.factory('apiFactory', ["$http", "$routeParams", ($http, $routeParams) ->
factory = {}
factory.getCustomers = ->
$http(
method: "GET"
url: "/customers.json"
).success( (data) ->
data
).error( (status) ->
console.log "Error"
factory.getCustomer = (customerId) ->
customerId = $routeParams.customerID
customer
factory
])
app.controller("CustomersController", ["$scope", "apiFactory", ($scope, apiFactory) ->
$scope.customers = apiFactory.getCustomers()
console.log $scope.customers
$scope.customer = apiFactory.getCustomer
console.log $scope.customer
])
In the following sample I replaced url by static json file but no luck either. Here is corresponding Plunker http://plnkr.co/edit/G6eFwR7uCNu32cLa1MvV?p=preview