问题描述:

Is there a nice solution to get rid of Angular $q promise service and start using EcmaScript6 native promises?

网友答案:

I would say rather than using $q custom promise, you could utilize the promise return by the $http/$resource call itself. Because that has been taken care $http/$resource internal implementation, as they will run digest once their promise rejected/resolved.

The only benefit I can see is, by having ES2015 promise is, you could use Arrow function's (=>), which is shorter and smarter syntax.

Code

var promise = $http.get('someUrl');
promise.then((data) = > { //success callback
   console.log(data)
}, (error) => { //error callback
   console.log(error)
})
相关阅读:
Top