当我运行此bookmarklet JavaScript时,模型不会更新角度范围。如何触发范围更新或摘要周期,以便视图模型知道更新的输入元素值?
//This doesn't work, but it does update the input box:
javascript:(function(){
var elementText = 'Changed text';
var inputElement = document.getElementById('inputBox');
inputElement.value = elementText;
})();
答案 0 :(得分:0)
我发现触发元素更改事件会触发Angular摘要周期:
javascript:(function(){
var elementText = 'Changed text';
var inputElement = document.getElementById('inputBox');
inputElement.value = elementText;
if ("createEvent" in document) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
inputElement.dispatchEvent(evt);
} else {
inputElement.fireEvent("onchange");
}
})();