我是Angular的新手,所以我需要一些帮助,我的问题是打电话给http get,我使用service是我的第一个get
我的第一项服务
getFirstData() { return this.http.get<FirstDataResults ('http://myurl.com/api/Classes/ads', httpOptions);
Run Code Online (Sandbox Code Playgroud)
我的组件TS文件
this.data.getFirstData().subscribe(
data => {
this.firsobjects = data.results;
},
err => console.error(err),
() => this.getComplementData(this.firstobjects)
);
Run Code Online (Sandbox Code Playgroud)
到现在为止,一切都很好,可以获取我的数据,完成后,我运行第二个函数getComplementData
我的第二次服务
getSecondData(idFirstObject: String) {
return this.http.get<ComplementDataResults>(
'http://myurl.com/api/Classes/Complement?' +
'where={'"idFirstObject":"' + idFirstObject + '"}',
httpOptions); }
Run Code Online (Sandbox Code Playgroud)
我的组件TS文件
getComplementData(firsobjects) {
this.number = 0;
for (var _i = 0; _i < firsobjects.length; _i++) {
this.data.getSecondData(firsobjects[_i].id).subscribe(
(data) => {
var a = (data.results);
this.firsobjects[this.number].complements = a;
}, err => console.log('error ' + err),
() => console.log('Ok ')
); …Run Code Online (Sandbox Code Playgroud) angular angular-httpclient angular4-httpclient angular5 angular6
我正在尝试HttpClient在Angular 7中使用JSON .代码工作正常,但我正在尝试实现注释代码并停止使用CONST IMAGES并直接从api获取此数据,我还不能这样做.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class ImageService {
// public _url: string = "https://jsonplaceholder.typicode.com/photos";
constructor(
// public http: HttpClient
) {}
theImages = [];
// IMAGES = [];
getImages(){
// this.IMAGES = this.http.get(this._url);
return this.theImages = IMAGES.slice(0);
}
getImage(id: number){
// this.IMAGES = this.http.get(this._url);
return IMAGES.slice(0).find(image => image.id == id);
}
}
const IMAGES = [
{
"albumId": 1,
"id": 1,
"title": "accusamus …Run Code Online (Sandbox Code Playgroud) typescript angular2-observables angular angular-httpclient angular7
我正在 Angular 6 中为我的公司构建一个媒体上传器,并在 s3 中将文件加载到我们的存储桶中。到目前为止,文件已成功上传并显示在 s3 控制台中,但 POST 请求始终返回“null”,即使它有效。
我想取回响应数据,因为我正在尝试跟踪上传进度,以在 UI 中显示用户。但是我无法从空响应中获取任何事件。
这是当前工作代码的样子。当我添加一个 console.log 并检查响应时它是“空”。我做错了什么,还是 s3 是这里的问题?
upload(url: string, data: any) {
const options = { reportProgress: true };
return this.http.post(url, data, options)
.map((response: Response) => response);
}Run Code Online (Sandbox Code Playgroud)
我正在努力使HTTP本机或HttpClient适用于我的应用程序。
如果我运行,ionic serve -c我的HttpClient在我的浏览器上可以正常运行,该浏览器位于localhost:8100和Ionic Dev App。如果我是为Android构建的,则HttpClient失败,因此我决定尝试使用HTTP Native。
然后,如果Ionic Dev App不支持该本地插件(在这里说),我不明白如何获得控制台日志,在我的浏览器上也看不到Cordova的原因。
有没有办法登录设备以调试HTTP Native?
我正在从头开始创建一个独立的应用程序,我没有 ngModule。
我正在创建一个翻译服务和一个使用它的管道。
在 app.component.ts 上测试它
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterOutlet } from '@angular/router';
import { I18nPipe } from './pipes/i18n.pipe';
import { I18nService } from './services/i18n.service';
@Component({
selector: 'ct-v4',
standalone: true,
imports: [CommonModule, RouterOutlet, I18nPipe],
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'ct-v4';
constructor(private i18nService: I18nService) {}
ngOnInit(): void {
this.i18nService.initLanguage('en');
}
}
Run Code Online (Sandbox Code Playgroud)
我的国际化服务:
import { Injectable } from '@angular/core';
import { HttpClient …Run Code Online (Sandbox Code Playgroud)