我想显示更新的数据而无需重新加载页面。我使用了Observables,但是没有用。谁能帮忙。我这样尝试过
我的ts文件
tryCatch({
data2_2 <- data1_2[[j]] %>% html_table(fill = TRUE)
if (grepl("Annual Income Statement", data2_2[1,1])){
data2_2 <- data2_2[4:nrow(data2_2),]
units <- data2_2[1,4]
units <- substr(units, regexpr("Actuals in ", units) + 11, nchar(units))
year <- data2_2[2,4]
fiscal <- data2_2[2,1]
sales_pos <- grep("Sales", data2_2[,1])
ebitda_pos <- grep("EBITDA", data2_2[,1])
ebit_pos <- grep("Operating profit", data2_2[,1])
ebt_pos <- grep("Pre-Tax Profit", data2_2[,1])
net_income_pos <- grep("Net income", data2_2[,1])
pe_ratio_pos <- grep("P/E ratio", data2_2[,1])
eps_pos <- grep("EPS", data2_2[,1])
sales <- as.numeric(gsub(" ", "", data2_2[sales_pos,4]))
ebitda <- as.numeric(gsub(" ", "", data2_2[ebitda_pos,4]))
ebit <- as.numeric(gsub(" ", "", data2_2[ebit_pos,4]))
ebt <- as.numeric(gsub(" ", "", data2_2[ebt_pos,4]))
net_income <- as.numeric(gsub(" ", "", data2_2[net_income_pos,4]))
pe_ratio <- as.numeric(gsub(",", ".", data2_2[pe_ratio_pos,4]))
eps <- (gsub(",", ".", data2_2[eps_pos,4]))
eps <- as.numeric(gsub(" ", "", eps))
}
}, error = function(e) {e; error_list_2 <<- c(error_list_2, j)})
我的服务
cat_update() {
let data= {
id: this.catdata[0]._id,
category_name:this.category_name
}
this.accountService.updatecategory(data).subscribe(response => {
alert("successfully updated")
}, err => {
alert("Something went wrong while update");
})
}
我的html文件
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DataService } from './data.service';
import { Observable } from 'rxjs';
import {map} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class AccountService {
public apiPath: string;
constructor(ds: DataService, public http: HttpClient) {
this.apiPath = ds.apiPath;
}
public dt(res:Response){
return res;
}
updatecategory(data): Observable<any> {
return this.http.post(this.apiPath + 'user/updatecategory',
data)
.pipe(map(this.dt)));
}
在我的html中,我编写了一种用于更新和添加类别部分的方法。更新和添加到数据库很好。但是我需要更新的数据而无需重新加载页面。