【问题标题】:Supplied parameters do not match any signature of call target in angular2提供的参数与 angular2 中调用目标的任何签名都不匹配
【发布时间】:2018-01-08 00:49:10
【问题描述】:

我创建了一个服务并尝试传递一个参数。当我尝试使用参数定义它时,我得到一个编译错误。

这很好用

createMovieCat(){
 /*     var headers = new Headers({"Access-Control-Request-Method" : "POST" ,  "Content-Type": "application/json" });
        const options = new RequestOptions( {headers: headers});
 */
        this._createURL = "http://localhost:8080/AdaRVM/api/movieCategory/create";
        this.emv  = new EmovieCat();
        this._http.post(this._createURL,JSON.stringify(this.emv)).subscribe(response =>{
            console.log(response.json());
        });
    }

当我向函数添加参数时,我得到标题中提到的编译错误。看起来很简单,但我看不出有什么问题,任何帮助都会得到帮助。谢谢。

createMovieCat(emv:EmovieCat){
 /*     var headers = new Headers({"Access-Control-Request-Method" : "POST" ,  "Content-Type": "application/json" });
        const options = new RequestOptions( {headers: headers});
 */
        this._createURL = "http://localhost:8080/AdaRVM/api/movieCategory/create";
       // this.emv  = new EmovieCat(); I removed this line 
        this._http.post(this._createURL,JSON.stringify(emv)).subscribe(response =>{
            console.log(response.json());
        });
    }

我的模特。

export class EmovieCat{

    id:String = "test";
    rev:String;
    dataModelVersion:number = 99;

}

【问题讨论】:

  • 您是否在代码中的任何地方使用该方法?因为错误表明您试图在不提供所有参数的情况下调用函数。
  • 你在函数调用中添加了这个参数吗?
  • 嗯,我在一个旧文件中有一个没有参数的调用,但编辑器没有警告我,谢谢。

标签: angular


【解决方案1】:

无论您在哪里使用,都需要使用参数更新方法,

createMovieCat(emv:EmovieCat)

比如说,如果你在组件内部使用

createMovieCat('PASSHERE');

【讨论】:

  • 您没有说明他遇到的错误是什么,并且您的示例不适合实现,因为 EmovieCat 不是字符串。
  • @cyrix 我不要求用户传递一个字符串,我只是评论传递正确的参数
  • 我确实阅读了完整的答案并说明了我的问题。
猜你喜欢
  • 2017-08-24
  • 2017-05-08
  • 2017-11-14
  • 2016-12-07
  • 2016-11-27
  • 2016-06-09
  • 2017-11-18
  • 2023-03-15
  • 2017-04-28
相关资源
最近更新 更多