Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 有人能解释lambda/fat-arrow角函数调用的语法和含义吗_Angular - Fatal编程技术网

Angular 有人能解释lambda/fat-arrow角函数调用的语法和含义吗

Angular 有人能解释lambda/fat-arrow角函数调用的语法和含义吗,angular,Angular,有人能帮我解释一下语法和意思吗?我知道,put$具有返回可观察对象的含义,因此它在公司服务中调用put,它有两个参数,我知道subscribe是什么意思,但我需要一些帮助来理解它 如果你有一个链接到一个好的教程,这将是伟大的 this.companyService.put$(this.currentId, this.appMenu.currentObject) .subscribe(selectedCompany => {this.appMenu.cu

有人能帮我解释一下语法和意思吗?我知道,
put$
具有返回可观察对象的含义,因此它在公司服务中调用put,它有两个参数,我知道subscribe是什么意思,但我需要一些帮助来理解它

如果你有一个链接到一个好的教程,这将是伟大的

this.companyService.put$(this.currentId, this.appMenu.currentObject)
                   .subscribe(selectedCompany => {this.appMenu.currentObject = selectedCompany});
这是服务:

如果您还可以解释“put”调用的语法,那也会很有帮助

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, BehaviorSubject } from 'rxjs';
import { Company } from '../models/company.model';

@Injectable({
  providedIn: 'root'
})
export class CompanyService {
  private url: string;

  constructor(private http: HttpClient) {
    this.url = "http://localhost:8080/niche/company";
  }

  getOne$ = (companyId: number): Observable<Company> => this.http.get<Company>(`${this.url}/${companyId}`);
  get$ = (): Observable<Company[]> => this.http.get<Company[]>(this.url);
  post$ = (company: Company): Observable<Company> => this.http.post<Company>(this.url, { company });
  patch$ = (companyId: number, company: Company): Observable<Company> => this.http.patch<Company>(`${this.url}/${companyId}`, { company });
  put$ = (companyId: number, company: Company): Observable<Company> => this.http.put<Company>(`${this.url}/${companyId}`, company );
  delete$ = (companyId: number): Observable<Company> => this.http.delete<Company>(`${this.url}/${companyId}`);
}
从'@angular/core'导入{Injectable};
从'@angular/common/http'导入{HttpClient};
从“rxjs”导入{observeable,BehaviorSubject};
从“../models/Company.model”导入{Company};
@注射的({
providedIn:'根'
})
出口类公司服务{
私有url:string;
构造函数(专用http:HttpClient){
this.url=”http://localhost:8080/niche/company";
}
getOne$=(companyId:number):Observable=>this.http.get(`${this.url}/${companyId}`);
get$=():Observable=>this.http.get(this.url);
post$=(company:company):可观察=>this.http.post(this.url,{company});
补丁$=(companyId:number,company:company):可观察=>this.http.patch(`${this.url}/${companyId}',{company});
put$=(companyId:number,company:company):可观察=>this.http.put(`${this.url}/${companyId},company);
delete$=(companyId:number):Observable=>this.http.delete(`${this.url}/${companyId}`);
}

以下行表示:

this.companyService
    .put$(this.currentId, this.appMenu.currentObject)
    .subscribe(selectedCompany => {
        this.appMenu.currentObject = selectedCompany
    });
如果你喜欢隐喻:

银行里有一首诗(
数据库
),您的抄本中有一份诗的副本(
客户端应用程序,在您的应用程序中是Angular应用程序

但是,您希望编辑您的文案和银行中的一些诗行

然后你打电话给银行账户管理员(
this.companyService
)将你的行(
.put
)放入现有的诗篇(
this.currentId,this.appMenu.currentObject
)中,然后你等待银行账户管理员(
.subscribe
)直到她/他更新银行的诗篇

更新:

@angular/common/http中的HttpClient提供了一个简化的客户端http 基于XMLHttpRequest的角度应用程序API 浏览器公开的接口。HttpClient的其他好处 包括可测试性功能、类型化请求和响应对象, 请求和响应拦截、可观察的API和简化的 错误处理

XMLHttpRequestXHR是用于客户端和服务器之间通信的javascript API。使用XMLHttpRequest (XHR)与服务器交互的对象。您可以从数据库中检索数据 无需进行完整页面刷新的URL。这将启用网页 只更新页面的一部分而不中断用户的工作 做。XMLHttpRequest在AJAX编程中大量使用

与它的名字相反,XHR可以用来接收JSON、HTML、纯文本以及XML

以及使用以下各项的示例:

// 1. Here we are creating a new XMLHttpRequest object
let xhr = new XMLHttpRequest();

// 2. Then we set its configuration: request of GET type for the URL /somePage/anotherPage
xhr.open('GET', '/somePage/anotherPage');

// 3. We are sending the request over the network
xhr.send();

// 4. Then this rows will be called after the response is received from the 
// server to the client
xhr.onload = function () {
    if (xhr.status != 200) { // see what HTTP status of the response is come
        alert(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
    } else { // show the result
        alert(`Great, got ${xhr.response.length} bytes`); // responseText is the server
    }
};

// Get progress from XMLHttpRequest
xhr.onprogress = function (event) {
    if (event.lengthComputable) {
        alert(`We are received ${event.loaded} of ${event.total} bytes`);
    } else {
        alert(`We are received ${event.loaded} bytes`); // no Content-Length
    }

};

xhr.onerror = function () {
    alert("Request failed");
};

因此
subscribe
HTTPClient的方法是
onload
XMLHttpRequest的方法

this.companyService
    .put$(this.currentId, this.appMenu.currentObject)
    .subscribe(selectedCompany => {
        this.appMenu.currentObject = selectedCompany
    });
如果你喜欢隐喻:

银行里有一首诗(
数据库
),您的抄本中有一份诗的副本(
客户端应用程序,在您的应用程序中是Angular应用程序

但是,您希望编辑您的文案和银行中的一些诗行

然后你打电话给银行账户管理员(
this.companyService
)将你的行(
.put
)放入现有的诗篇(
this.currentId,this.appMenu.currentObject
)中,然后你等待银行账户管理员(
.subscribe
)直到她/他更新银行的诗篇

更新:

@angular/common/http中的HttpClient提供了一个简化的客户端http 基于XMLHttpRequest的角度应用程序API 浏览器公开的接口。HttpClient的其他好处 包括可测试性功能、类型化请求和响应对象, 请求和响应拦截、可观察的API和简化的 错误处理

XMLHttpRequestXHR是用于客户端和服务器之间通信的javascript API。使用XMLHttpRequest (XHR)与服务器交互的对象。您可以从数据库中检索数据 无需进行完整页面刷新的URL。这将启用网页 只更新页面的一部分而不中断用户的工作 做。XMLHttpRequest在AJAX编程中大量使用

与它的名字相反,XHR可以用来接收JSON、HTML、纯文本以及XML

以及使用以下各项的示例:

// 1. Here we are creating a new XMLHttpRequest object
let xhr = new XMLHttpRequest();

// 2. Then we set its configuration: request of GET type for the URL /somePage/anotherPage
xhr.open('GET', '/somePage/anotherPage');

// 3. We are sending the request over the network
xhr.send();

// 4. Then this rows will be called after the response is received from the 
// server to the client
xhr.onload = function () {
    if (xhr.status != 200) { // see what HTTP status of the response is come
        alert(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
    } else { // show the result
        alert(`Great, got ${xhr.response.length} bytes`); // responseText is the server
    }
};

// Get progress from XMLHttpRequest
xhr.onprogress = function (event) {
    if (event.lengthComputable) {
        alert(`We are received ${event.loaded} of ${event.total} bytes`);
    } else {
        alert(`We are received ${event.loaded} bytes`); // no Content-Length
    }

};

xhr.onerror = function () {
    alert("Request failed");
};

所以
subscribe
HTTPClient
的方法是
onload
XMLHttpRequest

方法,那么currentObject是如何/为什么传递到subscribe()的呢?我理解基本概念。我希望得到更多关于机械的细节。也许,我需要更好地理解subscribe()调用?那么currentObject是如何/为什么传递给subscribe()的呢?我理解基本概念。我希望得到更多关于机械的细节。也许,我需要更好地理解subscribe()调用?它的基本rxjs/angular/typescript语法,你应该从它的基本rxjs/angular/typescript语法开始,你应该从