To call a method from the view would look something like this:
<li ng-class="{active: urlIsActive('/home/')}"><a href="#/home/">Home</a></li>
Then urlIsActive
would be a function in the scope, like this:
$scope.urlIsActive = function(url) {
return ($location.path().indexOf(url) == 0);
}
The problem with this approach is that the function urlIsActive
would have to be re-evaluated on every scope digest cycle, wasting a lot of performance. The approach they suggest is using events to manipulate scope variables instead, which is cheaper in terms of performance.
Note that the suggested scope variable manipulation occurs when an event is fired. When rendering the page, finding out if a link should be active is just a simple variable lookup, rather than actually executing a function (which has a lot of overhead in itself).