angular/angular.js — pull request #9488 by coditect (2014-10-08 05:09:28+00:00)
Title: feat($scope): propose and implement $when method

I have noticed that following pattern occurs in many of my AngularJS controllers
when I need to do initialization based on an asynchronously loaded resource:

if ($scope.someCondition == true) {
doSomething();
} else {
var unwatch = $scope.$watch('someCondition == true', function(newValue) {
if (newValue) {
doSomething();
unwatch();
}
});
}

I propose adding a $when() method to $scope to simplify handing of such cases:

$scope.$when('someCondition == true', doSomething);

This commit provides an initial implementation of the $when() method.