我將ng-click $ index值傳遞給我的控制器,然後將它的值用於ng-repeat中的數據但得到一個錯誤提示「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>
視圖輸出是示出了:
1 - Jan
2 - Feb
3 - Mar
etc
我的控制器具有以下提取代碼:
.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」不通過傳遞到第二視圖因此錯誤值「的ReferenceError:myChoice沒有定義」
請告知我哪裏錯了?謝謝。
應該是'的console.log($ scope.myChoice);',不是嗎? –
謝謝console.log($ scope.myChoice);現在有用。 – GreenDome