Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

safe $apply implementation #2023

@siongui

Description

@siongui

Hello,

I am writing custom event directive for keydown, blur, and focus. One problem the I often have is the following error:
Error: $apply already in progress

I am wondering whether the AngularJS team can add a "safe" apply function in Scope. Probably like the following implementation

$scope.safeApply = function(fn) {
  var phase = this.$root.$$phase;
  if(phase == '$apply' || phase == '$digest')
    this.$eval(fn);
  else
    this.$apply(fn);
};

Do you think is it better to provide this in AngularJS?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions