angular/angular.js — pull request #6732 by kamilkp (2014-03-18 08:30:46+00:00)
Title: feat(ngClass): one can pass an $element variable into ngClass expression functions

When using directives like `ngClick`, `ngFocus`, `ngKeydown`, `ngMousemove` etc. AngularJS passes a special `$event` object to any function that basically is an event listener.

One can then write in HTML
```html
ng-click="someHandler($event)"
```
and in javascript:
```javascript
$scope.someHandler = function(event){
var element = $(event.currentTarget);
// some other code
};
```
to get ahold of the HTML element (actually jQuery of jqLite object containing it) that the `ngClick` directive was applied to in the first place.

However in current version of AngularJS it is impossible to easily access that element using `ngClass` directive. This pull request makes it possible to pass a special `$element` object to any function in an `ngClass` expression so one can now write:

```html
ng-class="{'some-class': someCondition($element)}"
```

```javascript
$scope.someCondition = function(element){
if(conditionsThatElementMustMeet(element))
return true;
else
return false;
};
```

A real example might be a situation when one wants to apply a class to an element if and only if it's content is overflowing:

```css
#my-element{
overflow: hidden;
width: 50px;
display: inline-block;
white-space: nowrap;
text-overflow: ellipsis;
}
```
```html

{{modelBinding}}

```

```javascript
$scope.modelBinding = 'some string content'; // this could be user input
$scope.isOverflowing = function(element){
// actual check whether the element's content is overflowing
return element[0].scrollWidth > element[0].clientWidth;
};
```

Live code example here: http://jsfiddle.net/YAWGd/