Go back
Home
  • ionic
    • url不安全问题 caused by: unsafe value used in a resource URL context
    • 取整/取小数、与数值比较
    • null/undefined/空字符串的数值比较
    • Mac上chrome跨域请求
    • 遍历<a>标签,处理跳转操作
    • cli 常用命令
    • ionic-example
    • 报错: Unexpected value 'Http' imported ..
    • mac: python2环境问题
    • ionic3 解决Error: No provider for Http!
    • ts:for..in与for..of
    • [转]Mac OSX下重装node.js
    • pip使用举例
    • ES6 promise
    • 配置可滑动的segment
    • 开发小结(一)
      • Tutorial
        • 3.组件(一)
        • 1.Adding Pages
        • 6.组件(四):下拉刷新上上拉加载
        • 4.组件(二)
        • 5.组件(三):模态、导航、popover
        • 6.真机调试
        • 1.安装、启动、项目结构

ES6 promise

September 7, 2018
ionic

使用举例:

doSomething(id:string):Promise<{id:string}>{
   return new Promise((resolve => {
       console.log("do something");
       setTimeout(()=>{
           resolve({id:id});
       },2000);
   }));
}

//调用
this.doSomething("9527").then((res)=>{
    console.log(res); //{id: "9527"}
});     

额外的,配合return可以实现链式操作。

this.doSomething("9527").then((res)=>{
            console.log(res); //{id: "9527"}
            return this.doSomething("1913")
        }).then(res=>{
            console.log(res); //{id: "1913"}
        });

参考:

https://www.cnblogs.com/whybxy/p/7645578.html

https://rexdainiel.gitbooks.io/typescript/content/docs/promise.html