我的代碼如下。我遇到的問題是,只要modal.isOpen的值設置爲true,$ watch語句就不會觸發。我試圖避免使用範圍。$ apply。我在做什麼錯在這裏...
內部鏈接功能在角度指令:
link: function (scope, elem, attrs) {
scope.$watch('modal.isOpen', function(newValue, oldValue) {
if (newValue)
console.log("This does not trigger...");
}, true);
$document.bind('keydown', function (e) {
if(e.keyCode >= 48 && e.keyCode <= 90) {
scope.modal.isOpen = true;
elem.find('input')[0].focus();
}
..........
});
嘗試'$ scope.apply()' –
它的工作原理,但我試圖避免使用scope.apply。有沒有使用scope.apply的另一種方法? – user1142130
如果你想更新模型,你應該使用$ apply – sani