我正在尝试使用提交按钮添加新数据和选择获胜者按钮来选择新获胜者。两个按钮都显示,但是当我点击它们时没有任何反应。
这是我的 index.html 文件。
都是关于狗的!
<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>
My 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