【发布时间】:2019-09-28 18:31:49
【问题描述】:
有人可以帮我分解一下并解释语法和含义吗?我知道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}`);
}
【问题讨论】:
-
它的基本 rxjs / angular / typescript 语法,你真的应该从angular.io/tutorial开始
标签: angular