How would I have ui-router go to an external link, such as google.com?

Angular-ui-router doesn’t support external URL, you need redirect the user using either $location.url() or $window.open() I would suggest you to use $window.open(‘http://www.google.com’, ‘_self’) which will open URL on the same page. Update You can also customize ui-router by adding parameter external, it can be true/false. $stateProvider .state(‘external’, { url: ‘http://www.google.com’, external: true }) Then configure … Read more

Angularjs how to cancel resource promise when switching routes

First of all, I decided I needed to use $http since I couldn’t find any solution that used $resource, nor could I get it to work on my own. So here’s what my factory turned into, based on @Sid’s answer here, using the guide at http://www.bennadel.com/blog/2616-aborting-ajax-requests-using-http-and-angularjs.htm .factory(‘AllSites’,function($http,$q){ function getSites(categoryID) { // The timeout property of … Read more

How does Angular 2 change detection work?

Angular creates a change detector object (see ChangeDetectorRef) per component, which tracks the last value of each template binding, such as {{service.a}}. By default, after every asynchronous browser event (such as a response from a server, or a click event, or a timeout event), Angular change detection executes and dirty checks every binding using those … Read more

AngularJS : How to use one resolve for all the routes of my application

For completeness, here is the whole solution, using angular instead of underscore, with a chainable ‘when’. Nothing new in this code, just combined a bunch of the answers above. var originalWhen = $routeProvider.when; $routeProvider.when = function(path, route) { route.resolve || (route.resolve = {}); angular.extend(route.resolve, { CurrentUser : function(User) { return User.current(); } }); return originalWhen.call($routeProvider, … Read more

Why ng-transclude’s scope is not a child of its directive’s scope – if the directive has an isolated scope?

Why ng-transclude’s scope is not a child of its directive’s scope if the directive has an isolated scope? ng-transclude designed to allow directives to work with arbitrary content, and isolated scopes are designed to allow directives to encapsulate their data. If ng-transclude didn’t preserve scopes like that, any arbitrary content that you’re transcluding would need … Read more

Adding http headers to window.location.href in Angular app

When you use $window.location.href the browser is making the HTTP request and not your JavaScript code. Therefore, you cannot add a custom header like Authorization with your token value. You could add a cookie via JavaScript and put your auth token there. The cookies will automatically be sent from the browser. However, you will want … Read more

How to trigger a method when Angular is done adding scope updates to the DOM?

The $evalAsync queue is used to schedule work which needs to occur outside of current stack frame, but before the browser’s view render. — http://docs.angularjs.org/guide/concepts#runtime Okay, so what’s a “stack frame”? A Github comment reveals more: if you enqueue from a controller then it will be before, but if you enqueue from directive then it … Read more