[Angular Tutorial] 10-more templating

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.