Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs &引用;控制器为;不更新绑定_Angularjs - Fatal编程技术网

Angularjs &引用;控制器为;不更新绑定

Angularjs &引用;控制器为;不更新绑定,angularjs,Angularjs,我真的不知道为什么这不起作用。它应该会起作用 HTML 当this.Timer更新时,它不会在视图中更新。当我console.log()。如果我删除vm.Timer并简单地将其设置为Timer,并将其应用于$scope,而不是此,则它可以完美地工作,正如您自己所看到的: 我在另一个堆栈上做过多次,但由于某些原因,我不明白为什么它不起作用。我做错了什么?因为这不是你想象的那样此正在更改间隔回调中的上下文。要么使用箭头函数,要么设置一些上下文 $interval(() => { th

我真的不知道为什么这不起作用。它应该会起作用

HTML

this.Timer
更新时,它不会在视图中更新。当我
console.log()
。如果我删除
vm.Timer
并简单地将其设置为
Timer
,并将其应用于
$scope
,而不是
,则它可以完美地工作,正如您自己所看到的:


我在另一个堆栈上做过多次,但由于某些原因,我不明白为什么它不起作用。我做错了什么?

因为这不是你想象的那样<代码>此正在更改间隔回调中的上下文。要么使用箭头函数,要么设置一些上下文

$interval(() => {
    this.Timer = Math.round(new Date().getTime() / 1000.0);
}, 1000);


因为这不是你想象的那样<代码>此正在更改间隔回调中的上下文。要么使用箭头函数,要么设置一些上下文

$interval(() => {
    this.Timer = Math.round(new Date().getTime() / 1000.0);
}, 1000);


啊,该死!我习惯打字,所以当我回到古老的东西时,我忘记了所有的废话!多谢了,伙计,哈哈。@Mortenmolder——打字后回到常规JS就像拥有房子后搬回你的大学宿舍:)-总是乐于助人啊,该死!我习惯打字,所以当我回到古老的东西时,我忘记了所有的废话!多谢了,伙计,哈哈。@Mortenmolder——打字后回到常规JS就像拥有房子后搬回你的大学宿舍:)-总是很乐意帮忙
$interval(() => {
    this.Timer = Math.round(new Date().getTime() / 1000.0);
}, 1000);
$interval(function() {
    this.Timer = Math.round(new Date().getTime() / 1000.0);
}.bind(this), 1000);