Newbie issue

Can someone explain what I’m doing wrong here?

Controller has the following…

  .controller('ScoreCtrl',function($scope){
    $scope.scores.total = [];
    $scope.scores[0].total = 0;
    $scope.scores[1].total = 0;

    function addpoints(params){
      if(params = 1){
        $scope.scores[0].total=$scope.scores[0].total + 1;
      }
      if(params = 2){
        $scope.scores[1].total=$scope.scores[1].total + 1;
      }
    };

    function getpoints(params){
      if(params = 1){
        return scores[0];
      }
      if(params = 2){
        return scores[1];
      }
    };

  })

For the html view I just want to display score[0].total and score[1].total

      <ion-content ng-controller="ScoreCtrl">

        <div class="" >Team A: {{score[0].total}} Points</div>
        <div class="">Team B: {{score[1].total}} Points</div>
 </ion-content>

This doesn’t display anything, I’m assuming I have to use ng-repeat or try to use a function (like the get points one I’ve created?)

Help a newb out?

Thanks

You have to fill $scope.scores.total with data, or simply you could have two variables:

.controller('ScoreCtrl',function($scope){
    $scope.teamA = 0;
    $scope.teamB = 0;

    function addpoints(params){
      if(params = 1){
        $scope.teamA= $scope.teamA + 1;
      }
      if(params = 2){
        $scope.teamB = $scope.teamB + 1;
      }
    };

  })

And displaying in the view like this:

<ion-content ng-controller="ScoreCtrl">
        <div class="" >Team A: {{teamA}} Points</div>
        <div class="">Team B: {{teamB}} Points</div>
 </ion-content>

Ok how about if I wanted to do it as a json object or array like how I had
it?

Eventually there will be more than happy to one attribute to increment.

Sure, in that case you should declare the scores like this:

  $scope.scores = [];
    $scope.scores.push(
      {total: 0}
    );
    $scope.scores.push(
      {total: 0}
    );

and then use it in the view like this:

<ion-content ng-controller="ScoreCtrl">
        <div class="" >Team A: {{scores[0].total}} Points</div>
        <div class="">Team B: {{scores[1].total}} Points</div>
 </ion-content>