A query of Weather WebApp

Source: Internet
Author: User

First, WebApp introduction 1. Initial interface

2. Search results page

Ii. Project code 1. Project directory

--------App

----------App.component.ts

----------App.component.css

----------app.component.html

----------App.module.ts

2.app.component.html
1 <Divclass= "Content">2     <Div>3         <imgwidth= "+"src= "Data:image/svg+xml;base64, Phn2zyb4bwxucz0iahr0cdovl3d3dy53my5vcmcvmjawmc9zdmciihzpzxdcb3g9ijagmcayntagmjuwij4kicagidxwyxroigzpbgw9iinerdawmzeiigq9i k0xmjugmzbmmzeuosa2my4ybde0ljigmtizljfmmti1idizmgw3oc45ltqzljcgmtqumi0xmjmumxoiic8+ ciagica8cgf0acbmawxspsijqzmwmdjgiibkpsjnmti1idmwdjiyljitljfwmjmwbdc4ljktndmunyaxnc4ylteymy4xtdeynsazmhoiic8+ Ciagica8cgf0acagzmlsbd0ii0zgrkzgriigzd0itteynsa1mi4xtdy2ljggmtgyljzomjeun2wxms43lti5ljjondkungwxms43idi5ljjimtgztdeynsa1m i4xem0xnya4my4zac0zngwxny00mc45ide3idqwljl6iiavpgogidwvc3znpg== ">4     </Div>5     <H2>{{title}}</H2>6     <Div>7         <formclass= "Form-inline">8           <Divclass= "Form-group">9             <label for= "Exampleinput">Address</label>Ten             <inputtype= "text"class= "Form-control"ID= "Exampleinput"placeholder= "Please input the address"name= "Searchaddress"> One           </Div> A           <Buttontype= "button"class= "Btn Btn-default"(click)= "Start ()">Search</Button> -         </form> -     </Div> the </Div> - <Divclass= "Data"*ngif= "Begin"> -     <Tableclass= "Table table-striped"> -         <thead> +             <TR> -                 <th>Date</th> +                 <th>Weather</th> A                 <th>Daytime temperature</th> at                 <th>Night temperature</th> -                 <th>Barometric value</th> -                 <th>Humidity</th> -                 <th>Weather conditions</th> -             </TR> -         </thead> in         <tbody> -             <TR*ngfor= "Let DL of Datalist;let i=index;"> to                 <TD>{{Datestring[i]}}</TD> +                 <TD>{{Dl.weather[0].main}}</TD> -                 <TD>{{DL.temp.day}}</TD> the                 <TD>{{DL.temp.night}}</TD> *                 <TD>{{Dl.pressure}}</TD> $                 <TD>{{dl.humidity}}</TD>Panax Notoginseng                 <TD><imgsrc= "Http://openweathermap.org/img/w/{{dl.weather[0].icon}}.png"/></TD> -             </TR> the         </tbody> +     </Table> A </Div>

3.app.component.ts
1Import {Component, OnInit} from ' @angular/core ';2Import {HttpClient} from ' @angular/common/http ';3Import ' Rxjs/add/operator/topromise ';4 5 @Component ({6Selector: ' App-root ',7Templateurl: './app.component.html ',8Styleurls: ['./app.component.css ']9 })Ten Export Class appcomponent{ Onetitle = ' A Weather search app! '; A Public http; - Data:any; -begin=false;//controls whether the weather results list appears thesearchaddress:string;//variable declaration for Query box text -Datestring:string[];//Seven date array declarations for the weather results list -Datalist:any;//Gets the data list variable declaration - Constructor (private http:httpclient) { +          This. http =Http; -     } +now=NewDate ()//Get current Time A Getdatestr (adddaycount:number) { at          This. Now.setdate ( This. Now.getdate () +adddaycount);//get the date adddaycount days -Let y = This. Now.getfullyear (); -Let M = This. Now.getmonth () +1;//Gets the date of the current month -Let d = This. Now.getdate (); -         returny+ "Year" +m+ "month" +d+ "Day"; -     } inNgoninit () {//executes when the component is loaded in -          This. datestring=[ This. GETDATESTR (0), This. GETDATESTR (1), This. GETDATESTR (2), This. GETDATESTR (3), This. GETDATESTR (4), This. GETDATESTR (5), This. GETDATESTR (6)] to     } +Start () {//functions executed after clicking on the query -          This. searchaddress = (document.getelementsbyname (' searchaddress ') [0] as htmlinputelement). Value;//get the text inside the search box the         if( This. searchaddress.length!=0) {//if the text inside the search box is not empty, the result list appears and the request is sent *              This. begin=true;  $              This. Http.get ("http://api.openweathermap.org/data/2.5/forecast/daily?q=" + This. searchaddress+ "&mode=json&units=metric&cnt=7&appid=f12159c1f548ea9ab7b5ff1907b1df50")Panax Notoginseng. Subscribe (DATA) = { -                      This. Data=data; the                      This. datalist= This.  Data.list;  +                 }, AErr = { }); the}Else{//if the text inside the search box is empty, the result list does not appear and the request is not sent +Alert ("Please enter Address"); -         }    $     }  $}

4.app.component.css
1 . content{2    width:340px; 3     margin:0 Auto; 4 }5. data{6    width:800px; 7     margin:0 Auto; 8     margin-top:10px; 9 }
PS: Data interface in the Project Pro-test available, you can play the project code address HTTPS://GITHUB.COM/NANGXIF/WEATHERWEBAPP



A query of Weather WebApp

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.