http - 未找到 Angular Http 方法
问题描述
我已将此作为我的一个项目的核心项目,并且我坚持使用它。
我尝试使用 http 方法,但失败了。我尝试将 HttpClientModule 添加到 app.module 但仍然没有。
我得到的错误是:
app.ae014c5e7b696f87de83.bundle.js:107 ERROR TypeError:
Cannot read property 'method' of undefined
All I did in the app.component.ts file add
export class AppComponent extends BaseComponent implements OnInit {
constructor(
private readonly i18nStore: Store<I18NState>,
private readonly config: ConfigService,
private http: HttpClient,
@Inject(PLATFORM_ID) public platformId: Object
) {
super();
// TODO: ngx-i18n-router
// private readonly i18nRouter: I18NRouterService) {
}
ngOnInit(): void {
this.i18nStore.dispatch(new Init(this.config.getSettings('i18n')));
}
createUserA(): void {
this.http.get<any>('https://swapi.co/api/people/1')
.subscribe(data => console.log('data', data));
}
}
机器人获取和发布不起作用。我已经导入:
import { HttpClient } from '@angular/common/http';
解决方案
添加到您的app.component.ts
contructor(private http : HttpClient) {}
推荐阅读
- c++ - sscanf_s:格式字符串“%d”需要一个“int *”类型的参数,但可变参数 4 的类型为“WORD *”
- ibm-cloud - IBM Watson Assistant:如何通过对话进行 API 调用
- mysql - MySQL 从数据库中删除 where
- arrays - 循环遍历正则表达式中的数组内的对象
- java - 使用 launch4J 构建 java exe 文件时出现错误:“AWT-EventQueue-0” java.lang.NoClassDefFoundError: javax/persistence/NoResultException
- angular - Ionic 4 / Angular 7 中的枚举和 ngModel 数据绑定
- python - 如何在 Python 中使用多实例定义属性?
- angular - 无法解析 APICalls 的所有参数:(?)
- r - 将 lapply 调用的输出写入单个表
- mysql - MySQL - 根据查询参数值从两个可选记录中选择一个值