javascript - Wait for angular to finish updating the DOM - Stack Overflow

I need to attach bootstrap datepicker to one of my input fields that will be generated with AngularJS.D

I need to attach bootstrap datepicker to one of my input fields that will be generated with AngularJS.

Doing the following doesn't work because the element does not yet exist:

$(function () {
    $(':input[name=dispense_date]').datepicker();
});

Instead I must do:

$(function () {
    setInterval(function () {
        $(':input[name=dispense_date]').datepicker();
    }, 200);
});

The latter version works but is inefficient and not exactly the "correct" way to do this. Do angular controllers/modules have a method for running callbacks after everything pletes?

I need the jquery code to run after an $http.get() call, but simply adding it inside the .success() call won't do the trick since $apply hasn't ran yet.

I need to attach bootstrap datepicker to one of my input fields that will be generated with AngularJS.

Doing the following doesn't work because the element does not yet exist:

$(function () {
    $(':input[name=dispense_date]').datepicker();
});

Instead I must do:

$(function () {
    setInterval(function () {
        $(':input[name=dispense_date]').datepicker();
    }, 200);
});

The latter version works but is inefficient and not exactly the "correct" way to do this. Do angular controllers/modules have a method for running callbacks after everything pletes?

I need the jquery code to run after an $http.get() call, but simply adding it inside the .success() call won't do the trick since $apply hasn't ran yet.

Share Improve this question edited Jul 16, 2014 at 23:04 TheOne asked Jul 16, 2014 at 22:53 TheOneTheOne 11.2k21 gold badges85 silver badges122 bronze badges 2
  • 3 don't re-invent the wheel. angular-ui.github.io/bootstrap – charlietfl Commented Jul 16, 2014 at 23:09
  • 1 True, but I didn't like the look of their datepicker. – TheOne Commented Jul 17, 2014 at 22:30
Add a ment  | 

1 Answer 1

Reset to default 8

Use $timeout:

$timeout(function() {
    $(':input[name=dispense_date]').datepicker();
});

Angular will ensure that the timeout function executes after the pile/link phase and even after the render phase.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744274856a4566278.html

相关推荐

  • javascript - Wait for angular to finish updating the DOM - Stack Overflow

    I need to attach bootstrap datepicker to one of my input fields that will be generated with AngularJS.D

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信