Instantly share code, notes, and snippets.

@poonkave /app
Created Oct 10, 2014

Embed
What would you like to do?
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