【发布时间】:2018-12-09 12:33:40
【问题描述】:
这是我的 app.modules
const appRoutes: Routes = [
{ path: 'topic/:topicTypeAngular', component: StoryTypeComponent, pathMatch : 'full'},
{ path: '**', component: PageNotFoundComponent}
];
这是我在 html 中的导航
<ul>
<li> <a routerLink="topic/culture">Culture</a></li>
<li><a routerLink="topic/tech">Tech</a></li>
</ul>
//这是component.ts的摘录和关键部分
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpRequest, HttpEvent, HttpEventType, HttpParams } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
constructor(public http: HttpClient, private route: ActivatedRoute) {
this.parameter = this.route.snapshot.paramMap.get('topicTypeAngular');
let parameter = this.parameter;
}
ngOnInit() {
this.route.url.subscribe(parameter => {
let parameter = this.parameter;
this.http.get('http://localhost:3200/cookbooks/topic/'+parameter).subscribe(httpResponse => {
this.data = httpResponse;
console.log(httpResponse);
});
})
}
最后一部分没有为我提供新的 httpResponse 数据。 这个link 与我的问题类似,但不准确。但是,我尝试过但失败了。提前致谢
【问题讨论】:
-
你为什么不订阅
params呢?以及为什么不使用ngOnInit(),它是用来做这些事情的 -
我做了但没用
标签: angular http routing httpclient