var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/list', {
templateUrl: 'js/templates/list.html',
controller: 'appController'
}).
when('/add', {
templateUrl: 'js/templates/add.html',
controller: 'appController'
}).
otherwise({
redirectTo: '/list'
});
}]);
app.controller('appController', function($scope){
$scope.countriesList = [
{name: 'Germany', capital: 'Berlin', population: '81,305,856'},
{name: 'France', capital: 'Paris', population: '65,630,692'},
{name: 'Italy', capital: 'Rome', population: '61,261,254'},
{name: 'Spain', capital: 'Madrid', population: '47,042,984'},
{name: 'United Kingdom', capital: 'London', population: '63,047,162'}
];
$scope.addCountry = function(){
$scope.countriesList.push( { name: $scope.newCountry.name, capital: $scope.newCountry.capital } );
};
}); |