从指令更新范围

时间:2014-12-20 16:15:29

标签: angularjs

我已经在我的指令中定义了一个范围。

scope.selection = 3

当我将指令应用于元素时,

<div myDirective></div>

其模板将正确打印范围var。

<span>{{selection}}</span> //prints: 3

但是当我更新指令中的scope变量时,它不会在视图中更新。

element.bind("keydown", function(event){
    if(event.which === 38){ //up arrow
        scope.selection--;
        console.log(scope.selection); //logs the updated value but view stays the same
    }
}

我可以从指令中绑定范围吗?

编辑:

如果我查看其他浏览器标签,请返回应用程序,然后更新视图。

0 个答案:

没有答案
相关问题