这里发生了什么:
我希望“取消预订”按钮在点击后有一个超时.首次点击它会更改为显示“确认取消”按钮.几秒钟后,它返回“取消预订”.
我的控制台给了我:
TypeError: $timeout is not a function
我正在使用AngularJS $timeout:
控制器:
'use strict'; module.controller('ReservationItemCtrl',['$scope','$stateParams','$RPC',function($scope,$stateParams,$RPC,$timeout) { ......other stuff....... ......other stuff....... $scope.toggleCancelReservation = function(reservation) { reservation.clickedcancel = true; $timeout(function(){reservation.clickedcancel = false},4000); }; } ]);
模板:
<button ng-show="!reservation.value.deleted && !deleted.value" class="btn btn-danger" ng-show="canCancel(reservation)" ng-if="!reservation.clickedcancel" ng-click="toggleCancelReservation(reservation)"> Cancel With refund </button> <button type="button" class="btn btn-danger" ng-if="reservation.clickedcancel == true" ng-click="deleteReservation();" style="margin-top: -4px;"> Confirm Cancellation </button>
我准确地在第一次点击时切换按钮然后再次点击它会正确取消/删除预订,但如果我在第一次点击后没有做任何事情,那么超时永远不会将其返回到原始按钮.在我的控制台中,我看到$timeout因某种原因不是函数?我把它包含在我的控制器中.我错过了什么吗?
解决方法
你忘了$timeout的内联表示法:
'use strict'; module.controller('ReservationItemCtrl','$timeout',function ($scope,$timeout) { ......other stuff....... ......other stuff....... $scope.toggleCancelReservation = function (reservation) { reservation.clickedcancel = true; $timeout(function () { reservation.clickedcancel = false },4000); }; } ]);
原文地址:https://www.jb51.cc/js/150412.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。