Here is the link to the code:
http://plnkr.co/edit/usrmiNkj5YJY5SlV8ETw?p=preview
Open up your javascript console and click on "say hi". It will trigger an error that $apply is already in progress.
But when you remove this piece of code:
ng-controller="mouseEvents" ng-mousedown="onMouseDown()" ng-mouseup="onMouseUp()" ng-mousemove="onMouseMove()"
and after saving when you click on "say hi" the error is gone.
How can I solve this?
I need the mouseEvents to set flags if the mouse is down or if it is up for multiple different controllers. I can not simply remove it in my code.
Edit:
Newer angular version solved my issue without $timeout v1.3.10 or higher
Once you've added support for alerts to your app by following the previous steps, you can trigger the display of notifications from any angular component by injecting the alert service and calling one of it's methods for displaying different types of alerts, i.e: success (), error (), info () and warn ().
The AlertModule ( /src/app/_alert/alert.module.ts) encapsulates the alert component so it can be imported and used by other Angular modules. Subscribe to my YouTube channel or follow me on Twitter, Facebook or GitHub to be notified when I post new content.
A reference to the browser's window object. While window is globally available in JavaScript, it causes testability problems, because it is a global variable. In AngularJS we always refer to it through the $window service, so it may be overridden, removed or mocked for testing.
Next.js: Next.js Alert notifications are an extremely common requirement in web applications for displaying status messages to the user e.g. error, success, warning and info alerts. In this tutorial we'll cover how to implement a simple reusable alert notification module in Angular 10.
Use $timeout to let angular finish dirty checking then show the alert.
app.controller("demoController",function($scope,$window, $timeout){
$scope.save = function(){
$timeout(function(){
window.alert("hi!");
});
};
});
Plunkr: http://plnkr.co/edit/Kxbey5Rc43xsB9v5ugZ5?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With