Last active
November 7, 2015 05:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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