Angular: Empty Fiddle

http://angularjs.org/

by jvandyke

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
    Filter: <input ng-model='filterExpr'><button ng-click='items.push("car")'>Add sth to the list</button>
    <hr>
    <ul>
        <li ng-repeat='item in filtered = (items | filter:filterExpr)'>{{item}}</li>
    </ul>
    <hr>    
    Filtered list has {{filtered.length}} items
</div>

JavaScript

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {
    $scope.items = ['foo', 'bar', 'foobar'];

    $scope.$watch('filtered', function (newValue) {
        if (angular.isArray(newValue)) {
            console.log(newValue.length);
        }
    });
}