In angular1.5.8, when I call the interface to return data, if the request parameter is empty or undefined, then return, but the value returned by this return is empty and does not have .then, and an error is reported
Case code:
onGoodsNameAutoComplate = (value: string) => {
if (!this.clientId || !this.$scope.goodsTypeId) {
return;//这边返回就是空的,没有.then,则会报错
};
return this.goodsService.getList(this.clientId, value, this.$scope.goodsTypeId, 0, 5).then(res => {
return res.data.list;
})
}
Error code:
TypeError: Cannot read property 'then' of undefined
at T (angucomplete-alt.min.js:2)
at $ (angucomplete-alt.min.js:2)
at m.b.onFocusHandler (angucomplete-alt.min.js:2)
at fn (eval at compile (angular.js:14817), <anonymous>:4:233)
at b (angular.js:15906)
at e (angular.js:25885)
at m.$eval (angular.js:17682)
at m.$apply (angular.js:17782)
at HTMLInputElement.<anonymous> (angular.js:25890)
at HTMLInputElement.dispatch (jquery.min.js:3)
I want to be here:
if (!this.clientId || !this.$scope.goodsTypeId) {
return;//这边模拟返回一个空的promise对象,就不会报错了。。。
};
How to simulate an empty promise object? Find the solution! Thanks!
First of all, I am using ng1+ts here. I need to pay attention to injecting $q first
I found a better way