Angular JS - Passing the $ ng-click index value to a controller function, then back to another view

I pass the index value $ ng-click for my controller and then use its value in ng-repeat for my data from the array, but I get the error "ReferenceError: myChoice not defined"

In my view (months.html) there is a list of all months, when it is selected, it passes the value to the controller.

<ion-list ng-repeat="time in times.months" ng-click="getMonthId($index)" style="">
  <ion-item style="" href="#/dmtimes">{{ time.monthId }} - {{ time.MonthName }</ion-item>
</ion-list>

The view output shows:

1 - Jan
2 - Feb 
3 - Mar
etc

My controller has the following extraction code:

.controller('dailyMeetingTimesCtrl', function($scope, MeetingNames, $ionicLoading, $firebase, $firebaseArray) {

  $scope.getMonthId = function (monthId) {
    alert("you selected: " + monthId); // this works fine.
    $scope.myChoice = monthId; // ReferenceError: myChoice is not defined

    console.log(myChoice);
  }
})

In my second view (displayMeetingTimes.html) I want to display meeting details, time, etc. for the selected month. The code is as follows:

<ion-view title="Daily Meeting Times">
  <ion-content ng-controller="dailyMeetingTimesCtrl" class="has-header" overflow-scroll="true" padding="true">
    <ion-list>

      <ion-item ng-repeat="time in times.months(myChoice).days" class="item-text-wrap">
        <span>{{myChoice}}</span>
        Meeting Name:   {{ time.meetingName }}<br />
        Star Time:  {{ time.startTime }}<br />
        Finish Time:    {{ time.finishTime }}<br />
      </ion-item>         
    </ion-list>

  </ion-content>
</ion-view>

, "myChoice" , "ReferenceError: myChoice "

, , ? .

+4
1

$index ng-repeat, . , HTML :

<ion-list ng-repeat="time in times.months track by $index" ng-click="getMonthId($index)" style="">
  <ion-item style="" href="#/dmtimes">{{ time.monthId }} - {{ time.MonthName }
  </ion-item>
</ion-list>

-, , ReferenceError: myChoice is not defined, , myChoice. $scope.myChoice.
:

console.log($scope.myChoice);
+5

Source: https://habr.com/ru/post/1623104/


All Articles