首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在一个函数angular7中合并两个函数

如何在一个函数angular7中合并两个函数
EN

Stack Overflow用户
提问于 2019-05-28 00:34:16
回答 1查看 0关注 0票数 0

我尝试但没有任何工作,示例不正确的方式是在数据库中添加2条记录

我想将这两个函数合并为一个函数服务

代码语言:javascript
复制
 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);
    }

代码语言:javascript
复制
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条记录

代码语言:javascript
复制
   interface  

    export interface  INews{

    IDNews:number;
    IDCategoery:number; 
    NameNews:string; 
    TopicNews:string; 
    DateNews?:Date;
    ImageCaption:string;
    ImageName:string ;


    }

 

我尝试但没有任何工作,示例不正确的方式是在数据库中添加2条记录

EN

回答 1

Stack Overflow用户

发布于 2019-05-28 10:29:18

尝试forkJoin

代码语言:javascript
复制
  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;
        });
      }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档