Skip to content

Instantly share code, notes, and snippets.

@poonkave
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poonkave/e5f826deb146c7131054 to your computer and use it in GitHub Desktop.
Save poonkave/e5f826deb146c7131054 to your computer and use it in GitHub Desktop.
angular.module('contacts', ['ngRoute'])
.config(['$routeProvider',
function ($routeProvider) {
$routeProvider
.when('/detail/:id', {
templateUrl: 'detail.html',
controller: 'DetailsController'
});
}
]).controller('ContactSearch', function ($scope, dataService) {
$scope.contacts = [];
$scope.searchFor = "";
$scope.search = function () {
dataService.search($scope.searchFor)
.success(function (data, status, headers, config) {
$scope.contacts = data.contacts;
})
.error(function (data, status, headers, config) {
$scope.contacts = [];
});
};
}).controller('DetailsController', function ($scope, $routeParams, dataService) {
var id = $routeParams.id;
dataService.detail(id)
.success(function (data, status, headers, config) {
$scope.contact = data.contact[0];
})
.error(function (data, status, headers, config) {
// log error
});
}).factory('dataService', ['$http', function ($http) {
var dataService = {
search: function (searchFor) {
return $http.get('../search.php?searchfor=' + encodeURI(searchFor));
},
detail: function (id) {
return $http.get('../detail.php?id=' + id);
}
};
return dataService;
} ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment