香港专业教育学院创建了一个服务,这个功能
public crearNegocio(negocio,callback){
var user = JSON.parse(localStorage.getItem("currentUser"));
var id_usuario = user.objUser.id_usuario;
negocio.id_usuario = id_usuario;
this.http.post(this.config.initialConfig+"/negocio/create/",negocio)
.subscribe((response)=>{
callback(null,response)
},(error)=>{
callback(error)
})
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.1/angular.min.js"></script>
然后在组件我把它称为是这样的:
import { NegocioService } from '../negocio.service';
constructor(private negocioS:NegocioService) {}
crearNegocio(){
this.loader=true;
this.negocioS.crearNegocio(this.negocio,function(err,res){
if(!err){
this.loader=false;
console.log("res",res);
}else{
this.loader=false;
console.log(err)
}
});
}
它的工作原理,并插入到我的表,一切OK,但是当我使用了回调的服务功能,它没有做任何事情里面打印,它只是跳过它,也就是组件。
我已经去其他服务相同的代码及其callbaks做工精细。
我解决了它,这是两个问题,一个是我的后端与async.each。
但是,另一位是“本”。它以“本”从回调的话,因为它不是一个变量叫装载机它不会做任何事情。
crearNegocio(){
var self = this;
this.loader=true;;
this.negocioS.crearNegocio(self.negocio,function(err,res){
if(!err){
self.loader=false;
}else{
self.loader=false;
console.log(err);
}
});
}