【发布时间】:2018-04-04 22:16:20
【问题描述】:
无法在 html 页面中显示控制台结果 这是 TS 组件 (home.component.ts) 的代码
import { Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import {Router } from '@angular/router';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(
private http: Http,
public router:Router
) {}
ngOnInit() {}
source="";
destination="";
date="";
names="";
searchCity(){
this.http.get("http://127.0.0.1:8000/restapi/?source="+this.source+"&destination="+this.destination+"&date="+this.date+"")
.subscribe(
(res:Response) => {
this.router.navigate(['test']);
const searchFlight= res.json();
console.log(searchFlight);
//this.names = searchFlight.names;
}
)
}
}
<div class="hl1"></div>
{{names}}
{{prices}}
<div class="hl1"></div>
sss 是我得到的参数 (home.component.html)
<input type="text" placeholder="From ..." [(ngModel)]=source name="source">
<input type="text" placeholder="To ..." [(ngModel)]=destination name="destination">
<input type="text" class="input datepicker" value="Mm/Dd/Yy" [(ngModel)]=date name="date">
<button (click)=searchCity() type="submit">Search</button>
【问题讨论】:
-
那么
test路由组件的代码在哪里?还是路由到同一个组件? -
搜索完后会重定向到带有控制台结果的测试html页面
-
你能把这个放到 StackBlitz 上吗? StackBlitz
标签: javascript angular rest typescript