AngularJS empty fiddle

AngularJS empty fiddle

by Avi Algaly

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" ng-click='reset()' />
    <ul>
      <li ng-repeat="(key,val) in ret">{{key}} = {{val}}</li>
    </ul>
  </form>
</div>

JavaScript

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

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

  $scope.reset = function() {

    $scope.ret = [];
  }
  http: //jsfiddle.net/cmyworld/WdVDh/#run
    $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
    }
}]);