In this step, we will implement a view of the phone details, which is displayed when the user clicks on a phone in the list.
• When you click on a phone in the list, the phone details page with the phone-specific information will be displayed.
We're going to use $http to get our data to implement the phone detail view and then refresh the phonedetail component template.
The biggest differences are listed below, you can also click here to see all the differences from GitHub.
Data
except phones Span class= "pun" > json , app / phones / The directory also contains the JSON file for each step of the phone:
app/phones/nexus-s.json
: (Sample Fragment)
{ "additionalfeatures": "Contour Display, near Field Communications (NFC), ...", "Android": { "OS": " Android 2.3 ", " UI ":" Android " }, ... " Images ": [ " Img/phones/nexus-s.0.jpg ", " img/phones/nexus-s.1.jpg ", " Img/phones/nexus-s.2.jpg ", "Img/phones/nexus-s.3.jpg" ], "storage": { "flash": "16384MB", "Ram": "512MB" }}
Each of these files uses the same data structure to describe the various properties of each phone. We'll show the data in the phone details view.
Component Controller
We will use the $http service to extend the controller of the phonedetail component to get the correct JSON file, which is the same as the controller of the phonelist component.
app/phone-detail/phone-detail.component.js
:
Angular. Module (' Phonedetail '). Component (' Phonedetail ', { templateurl: ' phone-detail/phone-detail.template.html ', controller: [' $http ', ' $routeParams ', function Phonedetailcontroller ($http, $routeParams) { var = this; $http. Get (' phones/' + $routeParams. Phoneid + '. JSON '). Then (function (response) { self.phone = response.data; }); } ] });
In order to construct the URL for the HTTP request, we use the $routeParams. Phoneid, which is extracted from the current route by using the $route
service .
Component templates
Inline, the TBD placeholder template has been superseded by an extended external template that contains the list and bindings that make up the phone details. Notice how we use {{expression}} tags and ngrepeat to present our data model to the view layer.
Span class= "PLN" >app/phone-detail/phone-detail.. HTML
:
Summarize
Now that the phone details view is done, go to the next step and learn how to write your own display filter.
[Angular Tutorial] 10-more templating