Last active
January 3, 2016 02:09
-
-
Save robwormald/8394145 to your computer and use it in GitHub Desktop.
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
//simple employee factory using Restangular | |
innitApp.factory('Employee',function(Restangular){ | |
var _Employees = Restangular.all('employee') | |
return { | |
find : function(query){ | |
return _Employees.getList(query) | |
}, | |
findById : function(query){ | |
return Restangular.one('employee',query.id).get() | |
}, | |
create : function(obj){ | |
return _Employees.post(obj) | |
} | |
} | |
}) |
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
innitApp.controller('employeeCtrl',function($scope,$state,Employee){ | |
console.log('employeeCtrl') | |
Employee.find().then(function(employees){ | |
$scope.employees = employees; | |
$scope.selectedEmployee = $scope.employees[0] | |
}) | |
}) | |
innitApp.controller('employeeDetailCtrl',function($scope,$state,Employee){ | |
console.log($stateParams.id) | |
Employee.findById({id : $state.params.id}).then(function(employee){ | |
$scope.employee = employee; | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment