angularjs – Angular JS – 将ng-click $index值传递给控制器??
发布时间:2020-12-17 17:25:45 所属栏目:安全 来源:网络整理
导读:我将ng-click $index值传递给我的控制器,然后使用它在ng-repeat中的值来表示我的数据,但得到的错误表明“ReferenceError:myChoice未定义” 我的观点(months.html)有一个所有月份的列表,选中后,它会将值传递给控制器??. ion-list ng-repeat="time in times.m
|
我将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未定义” 请告诉我哪里出错了?谢谢. 解决方法
如果要使用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>
其次,你得到ReferenceError的原因:myChoice没有被定义,因为你从未初始化一个名为myChoice的变量.但是你有一个名为$scope.myChoice的变量. console.log($scope.myChoice); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- axis2的qname not fond for the package问题的解决
- MISCONF Redis is configured to save RDB snapshots, but
- centos系统为php安装memcached扩展步骤
- 序列化 – 你可以覆盖scala @serializable对象中的流编写器
- 得到bootstrap选择的字段
- Bash Scripting:要求脚本以root身份运行(或使用sudo)
- angularjs – 检测窗口焦点的角度方式?
- 在Scala中合并两个HashMaps
- scala在处理文件时是否提供异步非阻塞IO?
- jax-ws之webservice security(安全)教程第二天
