Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active January 3, 2016 02:09
Show Gist options
  • Save robwormald/8394145 to your computer and use it in GitHub Desktop.
Save robwormald/8394145 to your computer and use it in GitHub Desktop.
//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)
}
}
})
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