NaN显示偶数(angularjs)

时间:2015-12-08 00:46:47

标签: angularjs ionic nan

在控制器中:

$scope.startCount = 0;  

    $scope.vs = function (number) {  
        $scope.startCount = number; 
    } 

    $scope.startTimeout = function () {  
        $scope.startCount = $scope.startCount + 1;  
        mytimeout = $timeout($scope.startTimeout, 1000);  
    }  
    $scope.startTimeout();  

    $scope.stopTimeout = function () {  
        $timeout.cancel(mytimeout);  
        alert("Timer Stopped");  
    } 

$scope.meals = [
    { title: 'Abs', url:"#/app/mworkouts",id: 100, img: "img/female.jpg", vid:"vid/1.mp4",},
    { title: 'Arms', url:"#/app/browse",id: 2 , img: "img/male.jpg", vid:"vid/2.mp4"},
    { title: 'Biceps', url:"#/app/search",id: 3, img: "img/Spotify_2.jpg", vid:"vid/1.mp4" },
    { title: 'Legs', url:"#/app/search",id: 4, img: "img/Spotify_4.jpg", vid:"vid/2.mp4" },
    { title: 'Core', url:"#/app/mworkouts",id: 5, img: "img/female.jpg", vid:"vid/1.mp4" },
    { title: 'Back', url:"#/app/mworkouts",id: 6, img: "img/male.jpg", vid:"vid/2.mp4" }
  ];

在html中:

<div ng-repeat="m in meals">
<button ng-click='vs({{m.id}})'>Setter</button>
</div>

所以它应该如何工作是从数组中传入一个数字,然后使用$ timeout计数。如果我手动输入一个数字但我希望数字来自数组,它的工作完全正常。另外,{{m.id}}是一个数字,因为我测试了它{{m.id-60}}并且它有效。我不知道出了什么问题。

对于奇怪的名字感到抱歉......这只是一个例子:)

2 个答案:

答案 0 :(得分:0)

摆脱{{}}

    ng-click='vs(m.id)'

答案 1 :(得分:0)

这似乎对我有用!我为你添加了几个日志以确保

<div ng-repeat="m in meals">
     <button ng-click='vs(m.id)'>Setter</button>
 </div>

http://plnkr.co/edit/tpl:rfqcl9AHEoJZEEJxyNn2?p=preview