登录

javascript - angulars 页面不自动刷新

ng1,上代码:

//controller
this.PouchService.getSingleDoc(this.id)
    .then(res => {
        this.result = res;
        console.log(this.result); //这里能输出正确的数据
    });
//html,用了controller as
<p>{{home.result}}</p>

通过上边代码获取数据并绑定到页面上,数据在controller中已经更新了,但是页面没更新,不知道为什么。以前也总这么写,没有问题,难道是因为es6的事么?

# JavaScript
黄舟黄舟2146 天前440 次浏览

全部回复(2) 我要回复

  • 高洛峰

    高洛峰2017-04-11 10:21:11

    这点代码看不出啥毛病啊,你这es6也只是多了this的绑定的箭头函数。

    疑点:
    1、你这个this.PouchService不在ctrl中,而是某个子函数的作用域内
    2、页面有其他报错?其他原因阻塞了apply

    回复
    0
  • 高洛峰

    高洛峰2017-04-11 10:21:11

    只有调用NG封装的XHR事件才会轮询$switch,自己更新数据要更新到视图上就需要手动$scope.$digest或者$apply

    回复
    0
  • 取消回复发送