Friday, 16 August 2013

Angular.js reset button no effect on ng-repeat

Angular.js reset button no effect on ng-repeat

How is it possible to delete the ul element with the reset button in the
following code
<html ng-app>
<head>
<script src="http://code.angularjs.org/1.2.0rc1/angular.min.js"></script>
</head>
<body>
<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>
<script>
function Ctrl($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
}
}
</script>
</body>
</html>
Thank you in advance.

No comments:

Post a Comment