我对Angular很新,所以我需要的是spinner每次http请求完成时显示.
我有很多组件:
<component-one></component-one>
<component-two></component-two>
<component-three></component-three>
<component-n></component-n>
Run Code Online (Sandbox Code Playgroud)
每个人都有一个获取或保存一些数据的http请求,所以当我发出http请求时,我想显示我的<loading></loading>组件,所以我认为用一个http请求将我的加载组件注入到每个其他组件中是不好的做法.我可以添加一个过滤器或角度的东西,允许我<loading>在每个有http请求的组件中自动加载组件吗?
此外,当http请求完成时,我想显示"完成"或某些消息.
如果有人能为我提供解决方案,我将非常感激,ty.
我正在使用 TLSharp。我的目标是将文件发送给用户。我创建了 ASP.NET Core Web API 服务并在需要发送文件时发出 HTTP 请求。
它适用于一个文件,但每次当我在短时间内收到 2 个或更多请求时,我都会收到错误消息:
System.InvalidOperationException:校验和无效!跳过。
控制器:
[Route("upload/{driveId}")]
public async Task<ActionResult> Upload(string driveId)
{
var ms = new MemoryStream();
var file = service.Files.Get(driveId);
string filename = file.Execute().Name;
await file.DownloadAsync(ms);
ms.Position = 0;
new FileExtensionContentTypeProvider().TryGetContentType(filename, out var mime);
var stream = new StreamReader(ms, true);
await _client.SendFileToBot(filename, mime, stream, driveId);
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
SendFileToBot 方法:
public async Task SendFileToBot(string filename, string mime, StreamReader stream)
{
var found = await client.SearchUserAsync("username", 1);
//find user …Run Code Online (Sandbox Code Playgroud) 在 Angular 应用程序中,有多种方法可以从服务器获取数据:
这两种方法都对我有用,但我不明白我应该使用哪种方法。
第一种方法。从服务中获取 Observable 并在组件处订阅它:
article.service.ts
import { Injectable } from '@angular/core';
import { Article } from '../models/article';
import { AngularFirestore } from '@angular/fire/firestore';
import { map, take } from 'rxjs/operators';
import { Observable, Subject } from 'rxjs';
@Injectable({
providedIn: "root"
})
export class ArticleService {
public articlesChanged: Subject<Article[]> = new Subject<Article[]>();
articles: Article[];
constructor(private db: AngularFirestore) {}
get() {
return this.db.collection('articles').valueChanges({ idField: 'id' });
}
}
Run Code Online (Sandbox Code Playgroud)
home.component.ts
import { Component, …Run Code Online (Sandbox Code Playgroud)