let url = httpssilkroadcsdnnetapiv2assemblelistchannelsearch_hot_wordchannel_name=pc_hot_word&size=10&platform=pc; consolelog组件调用请求方法; thishttpgeturlsubscribedata = consolelog组件拿到请求返回数据;
根据代码中的报错信息,可以推断出http未被正确导入。解决办法如下:
- 确保在组件的顶部导入
HttpClient模块:
import { HttpClient } from '@angular/common/http';
- 在组件的构造函数中注入
HttpClient:
constructor(private http: HttpClient) { }
- 确保在组件中的
@NgModule装饰器中导入HttpClientModule:
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
HttpClientModule
],
// ...
})
export class YourComponent { }
通过以上步骤,应该可以解决http未定义的问题。
原文地址: https://www.cveoy.top/t/topic/i0vI 著作权归作者所有。请勿转载和采集!