Skip to content

Instantly share code, notes, and snippets.

@jonathansolorzn
Last active November 7, 2015 05:37
Show Gist options
  • Save jonathansolorzn/b375414a4a2648f2f131 to your computer and use it in GitHub Desktop.
Save jonathansolorzn/b375414a4a2648f2f131 to your computer and use it in GitHub Desktop.
Angular Controller that needs improvements. Here's the ReadProductFactory -> https://goo.gl/etvuqq
(function () {
'use strict';
angular
.module( 'app.purchases.products' )
.controller( 'ReadProductController', ReadProductController );
//Check out the description to go to ReadProductFactory
ReadProductController.$inject = [ '$scope', 'ReadProductFactory' ];
function ReadProductController( $scope, ReadProductFactory ) {
/* jshint validthis: true */
var vm = this;
vm.products = {};
vm.product = {};
vm.getProductsList = getProductsList;
vm.getProductDetails = getProductDetails;
function getProductsList( columnOrder, sortOrder ) {
var data = {
columnOrder: columnOrder,
sortOrder: sortOrder
};
ReadProductFactory.listProducts( data, success, fail );
//The following are the callbacks funcs but they repeat for the getProductDetails func too, should i set them global?
function success( products ) {
vm.products = products;
}
function fail( error ) {
console.log( error );
}
}
function getProductDetails( id ) {
var data = {
id: id
};
ReadProductFactory.detailProduct( data, success, fail );
function success( product ) {
vm.product = product;
}
function fail( error ) {
console.log( error );
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment