Angular: Solving "$digest already in progress" error
TL;DR You shouldn't call $scope.$apply()
or $scope.$digest()
inside a function that can be invoked by Angular – e.g. in an ngClick
.
The linked Stackoverflow answer has a quick overview of techniques to apply changes to a scope. It also explains what might be wrong when you're getting the error $digest already in progress
and gives some information that every Angular developer should know.
Related cards:
Rails: How to check if a certain validation failed
If validations failed for a record, and you want to find out if a specific validation failed, you can leverage ActiveModel's error objects.
You rarely need this in application code (you usually just want to print error messages), but it can be u...
Solving "cannot remove Object::ClassMethods"
Most likely you run rake
and your code is causing an exception which is not the one shown in your terminal.
Rails tries to catch this exception and clean up constants but -- while it's still booting up -- fails on this which causes another exce...
Angular: Fixing "Referencing DOM nodes in Angular expressions is disallowed"
Reason
If you are using Coffeescript, it is likely to be the culprit. Since Coffeescript always returns the value of the last expression, it may return DOM nodes:
# coffeescript
scope.focus = ->
element.focus()
# javascript
scope.focus...
Implementing upload progress and remove button with ActiveStorage DirectUpload
DirectUpload allows you to upload files to your file storage without having to wait for the form to submit. It creates AJAX requests to persist the file within your form and wraps them in a little API. This card will show you how to use it in orde...
Angular with haml: Dynamic html classes
A haml angular 1 template with
.thing(class="is-{{:: item.type }}")
will be compiled (by haml) to
<div class="is-{{:: item.type thing }}"></div>
which is not what you want! It will also crash in angular (unless thing
is a val...
Custom error messages in RSpec or Cucumber steps
Sometimes you have a test expectation but actually want a better error message in case of a failure. Here is how to do that.
Background
Consider this test:
expect(User.last).to be_present
In case of an error, it will fail with a n...
Error installing gem with native extension (collect2: error: ld returned 1 exit status)
If you have problems installing a gem and get a error collect2: error: ld returned 1 exit status
it's due to missing development headers of a library (ld
is the linker).
For example, with this output:
$ gem install json
Building native ...
Understanding the Selenium error "Modal Dialog Present" (aka Selenium::WebDriver::Error::UnhandledAlertError)
So your Cucumber feature sometimes dies with this exception:
Modal Dialog Present (Selenium::WebDriver::Error::UnhandledAlertError)
As a seasoned Selenium veteran you are used to misleading error messages. Hence you might be surprised ...
Ruby 2.3 brings Array#dig and Hash#dig
#dig
lets you easily traverse nested hashes, arrays, or even a mix of them. It returns nil
if any intermediate value is missing.
x = {
foo: {
bar: [ 'a', { baz: 'x' } ]
}
}
x.dig(:foo, :bar) # => [ 'a', { baz: 'x' } ]
x.dig(:foo,...
AngularJS: How to hook to the end of a digest cycle (before the browser redraws)
When you run code inside a $watch
expression that forces a repaint (e.g. by computing an element's width, or running something like...