我尝试但没有任何工作,示例不正确的方式是在数据库中添加2条记录
我想将这两个函数合并为一个函数服务
services.ts
baseUrlNews='http://localhost:5525/api/News';
addNe(_IModu: INews){
var body = JSON.stringify(_IModu);
var headerOptions = new Headers({'Content-Type': 'application/json'});
var requsetOptions = new RequestOptions({method : RequestMethod.Post,headers :headerOptions});
return this.http.post(this.baseUrlNews,body,requsetOptions).pipe(map(x => x.json()));
}
/*/*/*/*
<br>
postFile(caption: string, fileToUpload: File){
const endpoint = 'http://localhost:5525/api/UploadImage';
const formData: FormData = new FormData();
formData.append('Image',fileToUpload,fileToUpload.name);
formData.append('ImageCaption',caption);
return this.http.post(endpoint,formData);
}
component.ts
OnSubmit2(Caption,Image){
this._Neservice.postFile(Caption.value,this.fileToUpload).subscribe(
data =>{
console.log('done');
Caption.value=null;
Image.value = null;
this.toastr.success("New IMAGE Added Successfuly", "IMAGE");
}
)
}
OnSubmit(form :NgForm){
if (form.value.ID == null ){
this._Neservice.addNe(form.value).subscribe(data =>{
this.resetForm(form);
this.toastr.success("New Record Added Successfuly", "Ne");
})
我尝试但没有任何工作,示例不正确的方式是在数据库中添加2条记录
interface
export interface INews{
IDNews:number;
IDCategoery:number;
NameNews:string;
TopicNews:string;
DateNews?:Date;
ImageCaption:string;
ImageName:string ;
}
我尝试但没有任何工作,示例不正确的方式是在数据库中添加2条记录
发布于 2019-05-28 10:29:18
尝试forkJoin
export class App {
public propOne: string;
public propTwo: string;
public propThree: string;
constructor(private _myService: MyService) {}
ngOnInit() {
forkJoin(
this._Neservice.method1('Request One', 2000),
this._myService.method2('Request Two', 1000),
this._myService.method3('Request Three', 3000)
)
.subscribe(([res1, res2, res3]) => {
this.propOne = res1;
this.propTwo = res2;
this.propThree = res3;
});
}
}
https://stackoverflow.com/questions/-100006822
复制相似问题