-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (23 loc) · 720 Bytes
/
app.js
File metadata and controls
29 lines (23 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
myApp = angular.module('demo',[]);
myApp.config(function($routeProvider) {
$routeProvider.
when('/', {controller: ListCtrl, templateUrl: 'list.html'}).
when('/:id', {controller: DetailCtrl, templateUrl: 'detail.html'}).
otherwise({redirectTo:'/'});
});
myApp.factory('movies', function() {
return [
{id:1, name:"Star Wars"},
{id:2, name:"Empire Strikes Back"},
{id:3, name:"Star Wars 6"}
];
});
function ListCtrl($scope, movies) {
$scope.movies = movies;
$scope.addMovie = function() {
movies.push({id:5, name:"Star Trek"});
};
}
function DetailCtrl($scope, movies, $routeParams) {
$scope.selected = movies[$routeParams.id - 1];
}