Skip to content

Instantly share code, notes, and snippets.

@poonkave
Created October 10, 2014 11:15
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/0d831ea526f9b9b97cc0 to your computer and use it in GitHub Desktop.
Save poonkave/0d831ea526f9b9b97cc0 to your computer and use it in GitHub Desktop.
var contactsApp = angular.module('contacts', ['ngRoute']);
contactsApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/detail/:id', {
templateUrl: 'templates/detail.html',
controller: 'DetailsController'
})
}
]);
contactsApp.controller('ContactSearch', function($scope, $http) {
$scope.contacts = [];
$scope.searchFor = "";
$scope.search = function() {
var searchFor = $scope.searchFor;
$http.get('../search.php?searchfor=' + encodeURI(searchFor)).
success(function(data, status, headers, config) {
$scope.contacts = data.contacts;
}).
error(function(data, status, headers, config) {
// log error
$scope.contacts = [];
});
}
});
contactsApp.controller('DetailsController', function($scope, $http, $routeParams) {
var id = $routeParams.id;
$http.get('../detail.php?id=' + id).
success(function(data, status, headers, config) {
$scope.contact = data.contact[0];
}).
error(function(data, status, headers, config) {
// log error
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment