从jquery脚本调用angular函数,并等待它完成

时间:2016-06-01 06:51:34

标签: jquery angularjs scroll

每次我在输入标记中按angular时,我想从jquery拨打Enter功能。然后我想滚动到我的页面底部。我的脚本如下:

$(document).ready(function () {
    $(".scroll").keypress(function (e) {
        if (e.which == 13) {
            $.when( angular.element($("#myctrl")).scope().someAngularFunction()).done(function(){
                $("html, body").delay(2000).animate({ scrollTop: $('.bottomOfPage').offset().top }, 2000);
            }
            )}

    });
});

此代码正常运行, 但是当我删除延迟时,滚动不起作用。当然,保留硬编码延迟不是一种选择。

1 个答案:

答案 0 :(得分:0)

在页面的第一页 -

if (false || !!document.documentMode) {
            function CustomEvent() {
                var event = document.createEvent('HTMLEvents');
                event.initEvent('AngularLoaded', true, true );  
                return event;
            };

            //   CustomEvent.prototype = window.Event.prototype;
            document.angularLoaded = CustomEvent();
        }
        else {
            var event = new Event("AngularLoaded");
            document.angularLoaded = event;
        }

当你想在加载后使用角度函数

document.addEventListener('AngularLoaded', function() {
//your code goes here