AngularJS empty fiddle

AngularJS empty fiddle with myApp

by klode

HTML

<div ng-app="myApp">
    <form ng-submit="submit()" ng-controller="Ctrl">
        Enter text and hit enter:
        <input type="text" ng-model="text" name="text" />
        <input type="submit" id="submit" value="Submit" />
        <input type="reset" id="reset" value="Reset" />
        <ul>
            <li ng-repeat="(key,val) in ret">{{key}} = {{val}}</li>
        </ul>
    </form>
</div>

JavaScript

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

//app.directive('myDirective', function() {});
//app.factory('myService', function() {});

app.controller('Ctrl', ['$scope', function ($scope) {
    $scope.ret = {}

    $scope.reset = function () {
        $scope.ret = {}
    }

    $scope.submit = function () {
        var str = $scope.text;
        var ret = $scope.ret
        for (x = 0, length = str.length; x < length; x++) {
            var l = str.charAt(x);
            ret[l] = (isNaN(ret[l]) ? 1 : ret[l] + 1);
        }
        $scope.ret = ret
    }
}]);