ruby on rails - AngularJS Submit button -
i'm trying use submit button add new data , pick winner button pick new winner. both buttons show , when click on them nothing happens.
here index.html file.
it's dogs!
<div ng-controller="dogctrl"> <form ng-submit="adddog()"> <input type="text" ng-model="newdog.name"> <input type="submit" value="add"> </form> <ul> <li ng-repeat="dog in dogs"> {{dog.name}} <span ng-show="dog.winner" class="winner">winner</span> </li> </ul> <button ng-click="drawwinner()">draw winner</button> </div> js.coffee file. @dogctrl = ($scope) -> $scope.dogs = [ {name: "babytheboxer"} {name: "raleighthejack"} {name: "frankie"} ] $scope.adddog = -> $scope.dogs.push($scope.newdog) $scope.newdog = {} $scope.drawwinner = -> dog = $scope.dogs[math.floor(math.random()*$scope.dogs)] dog.winner = true
the problem see in line in js.coffee
:
dog = $scope.dogs[math.floor(math.random()*$scope.dogs)]
this should have given javascript errors because $scope.dogs
array. i'm assuming want array length here.
so try:
dog = $scope.dogs[math.floor(math.random()*$scope.dogs.length)]
Comments
Post a Comment