Controller expression evaluation on render with Angular

This is a really common need that AngularJS is not providing out of the box. I needed it myself for some projects and you might too? Ok, even if many will tell you that you should not program in a way that needs to use this feature, I beleive that there is plenty of people that knows exactly what they are doing. There is plenty of cases that have real and justified reasons to use this feature and they can use it properly. In short, when adequate this do not necessarily implies bad design. So here we go.

March 11, 2015 · 3 min

Controller based title change with Angular

Here is a tip on how to keep nice titles in your AngularJS-based SPA - Single Page Application. The strategy is this: Remember current title (whatever it might be) Set the title to whatever new value you want Observe when the controller gets destroyed and React restoring that previous value in the title controllers.controller('AmazingDetailController', [ '$scope', '$window', function ($scope, $window){ ...

November 21, 2014 · 1 min

Controller-Based Title Change in Angular

Here is a tip on how to keep nice titles in your AngularJS-based SPA - Single Page Application. The strategy is this: Remember current title (whatever it might be) Set the title to whatever new value you want Observe when the controller gets destroyed and React restoring that previous value in the title controllers.controller('AmazingDetailController', [ '$scope', '$window', function ($scope, $window){ // Sets this controller with the expected initial state // and perform any other initial activity needed $scope.initialize = function () { // Remember the previous title (whatever it might be) $scope.previousTitle = $window.document.title; $window.document.title = 'Amazing Detail!'; // Observes $destroy to restore the title of the page to its original // value once user navigates out of this controller $scope.$on('$destroy', function() { $window.document.title = $scope.previousTitle; }); }; // Does specific behavior 1 // Does specific behavior 2 // ... // Does specific behavior N $scope.initialize(); }]); A realistic use will probably be use a model that is coming from a service from the backend (or cache) or collaborating with other objects somehow. But this strategy is still valid, clean and works like a charm. ...

November 21, 2014 · 1 min