我创建了一个服务并尝试传递一个参数。当我尝试使用参数定义它时,出现编译错误。
这工作正常
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;
}
无论在哪里使用它,您都需要使用参数更新方法,
createMovieCat(emv:EmovieCat)
例如,如果您在组件内部使用
createMovieCat('PASSHERE');