Skip to content

Instantly share code, notes, and snippets.

@vayu-technology vayu-technology/controller.js Secret
Created Dec 5, 2014

Embed
What would you like to do?
AngularJS Woes
.controller('ProductCtrl', function($scope, $stateParams, $http, Products) {
$scope.product = Products.get($stateParams.productId);
});
<ion-view>
<ion-content class="has-header">
<h1>{{ product.title }}</h1>
</ion-content>
</ion-view>
angular.module('starter.services', [])
/**
* A simple example service that returns some data.
*/
.factory('Products', function($http) {
return {
get: function(productId) {
var product = null;
// example json returned
// {"id":"cover-702e5d","title":"Round Cushion Cover with red flower"}
// Simple index lookup
$http({
url: "http://localhost:3000/api/merchants/products/"+ productId +".json",
method: "GET",
headers: {
'Accept': 'application/vnd.foo.v1',
'X-AUTHENTICATION-TOKEN': 'foobar'
}
}).success(function(data, status, headers, config){
console.log(status);
}).then(function(response){
product = response.data;
console.log(response.data);
})
return product;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.