当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - How to implement EcmaScript2015 promises in Angular?

问题描述:

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)
})
分享给朋友:
您可能感兴趣的文章:
随机阅读: