Angularjs Angular JS-将ng click$索引值传递给控制器函数,然后返回到另一个视图

Angularjs Angular JS-将ng click$索引值传递给控制器函数,然后返回到另一个视图,angularjs,ionic,Angularjs,Ionic,我将ng click$索引值传递给我的控制器,然后在ng中使用它的值从数组中重复我的数据,但得到一个错误,提示“ReferenceError:myChoice未定义” 我的视图(months.html)有一个所有月份的列表,选中后,它会将值传递给控制器 <ion-list ng-repeat="time in times.months" ng-click="getMonthId($index)" style=""> <ion-item style="" href="#/dm

我将ng click$索引值传递给我的控制器,然后在ng中使用它的值从数组中重复我的数据,但得到一个错误,提示“ReferenceError:myChoice未定义”

我的视图(months.html)有一个所有月份的列表,选中后,它会将值传递给控制器

<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>
我的控制器具有以下提取代码:

.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);
  }
})
在我的第二个视图(displayMeetingTimes.html)中,我想显示所选月份的会议详细信息、时间等。代码如下:

<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}}
会议名称:{time.meetingName}}
星时间:{{Time.startTime}}
完成时间:{Time.finishTime}}
运行应用程序时,“myChoice”的值没有传递到第二个视图,因此出现错误“ReferenceError:myChoice未定义”


请告诉我哪里出了问题?谢谢。

当您想使用
ng repeat
传递
$index
时,您需要指定它。因此,您的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>

应该是
console.log($scope.myChoice),否?谢谢,console.log($scope.myChoice);现在可以了。谢谢…我已经按照建议对HTMl进行了更改,但是在我的第二个HTMl文件中,我如何读取myChoice值?也就是说,不工作…
不要在视图中放置
$scope
。当您访问
$scope
变量时,您没有将
$scope
放在html中。我已经尝试过了,我得到一个错误:“TypeError:v12.months不是一个函数”,这对我来说没有多大意义。你知道为什么吗?谢谢。不同的视图有不同的控制器吗?我需要更多的信息来帮助你。我没有什么好讨论的。两个视图都有一个控制器:
.controller('dailymetingtimesctrl',function($scope,MeetingNames,$ionicLoading,$firebase,$firebaseArray){$scope.getMonthId=function(monthId){alert(“您选择的:“+monthId”);$scope.myChoice=monthId;console.log(myChoice);}}
<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>
console.log($scope.myChoice);