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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -