Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AngularJS Tutorial Part 5 - Creating Individual Pages for Characters …
…and Movies
- Loading branch information
1 parent
0c50a4c
commit 1b04e6d
Showing
8 changed files
with
186 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
angularApp.controller('CharacterCtrl', [ | |||
'$routeParams', | |||
'$scope', | |||
'SwapiService', | |||
function($routeParams, $scope, SwapiService){ | |||
|
|||
$scope.character = {}; | |||
$scope.loading = true; | |||
$scope.id = $routeParams.id; | |||
|
|||
SwapiService.people() | |||
.then(function(data) { | |||
angular.forEach(data.data.results, function(person) { | |||
if (person.name.toLowerCase() === $routeParams.id.toLowerCase()) { | |||
angular.copy(person, $scope.character); | |||
console.log(person); | |||
} | |||
}); | |||
$scope.loading = false; | |||
}); | |||
} | |||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
angularApp.controller('MovieCtrl', [ | |||
'$routeParams', | |||
'$scope', | |||
'SwapiService', | |||
function($routeParams, $scope, SwapiService){ | |||
|
|||
$scope.movie = {}; | |||
$scope.loading = true; | |||
$scope.id = $routeParams.id; | |||
|
|||
SwapiService.films() | |||
.then(function(data) { | |||
angular.forEach(data.data.results, function(film) { | |||
if (film.episode_id == $routeParams.id) { | |||
angular.copy(film, $scope.movie); | |||
} | |||
}); | |||
$scope.loading = false; | |||
}); | |||
} | |||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
<div class="col-md-10 col-md-offset-1" ng-if="loading"> | |||
<div class="page-header"> | |||
<h1>Loading...</h1> | |||
</div> | |||
</div> | |||
|
|||
<div class="col-md-10 col-md-offset-1" ng-if="!loading"> | |||
<div ng-if="character.name"> | |||
|
|||
<div class="page-header"> | |||
<h1>{{ character.name }}</h1> | |||
</div> | |||
|
|||
<p><a href="#/">Home</a><p> | |||
|
|||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Name: {{ character.name }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Height: {{ character.height }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Mass: {{ character.mass }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Hair Color: {{ character.hair_color }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Eye Color: {{ character.eye_color }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Birth Year: {{ character.birth_year }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Gender: {{ character.gender }} | |||
</div> | |||
</div> | |||
|
|||
</div> | |||
|
|||
<div ng-if="!character.name"> | |||
|
|||
<div class="page-header"> | |||
<h1>No one by the name {{ id }} exists :(</h1> | |||
</div> | |||
|
|||
<a href="#/">Return Home?</a> | |||
|
|||
</div> | |||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
<div class="col-md-10 col-md-offset-1" ng-if="loading"> | |||
<div class="page-header"> | |||
<h1>Loading...</h1> | |||
</div> | |||
</div> | |||
|
|||
<div class="col-md-10 col-md-offset-1" ng-if="!loading"> | |||
<div ng-if="movie.title"> | |||
<div class="page-header"> | |||
<h1>Episode {{ id }}: {{ movie.title }}</h1> | |||
</div> | |||
|
|||
<p><a href="#/">Home</a><p> | |||
|
|||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Name: {{ movie.title }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Opening Crawl: | |||
<p> | |||
{{ movie.opening_crawl }} | |||
</p> | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Director: {{ movie.director }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Producer: {{ movie.producer }} | |||
</div> | |||
</div> | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
Release Date: {{ movie.release_date }} | |||
</div> | |||
</div> | |||
|
|||
|
|||
</div> | |||
|
|||
<div ng-if="!movie.title"> | |||
|
|||
<div class="page-header"> | |||
<h1>There is no Episode {{ id }} yet :(</h1> | |||
</div> | |||
|
|||
<a href="#/">Return Home?</a> | |||
|
|||
</div> | |||
</div> |