[英]scope variable gets undefined inside function - AngularJS
I need to call a function with scope variables. 我需要使用范围变量调用一个函数。 Its getting undefined inside function there. 它的内部函数在那里变得不确定。
setstates($scope.events.myevent,bannerslidesmyevent,$scope.eventPlus,$scope.myeventtime,myeventcurrenttime);
Definition: 定义:
function setstates(event,banner,eventplus,eventtime,currenteventtime)
{
if(event ===null || event ==='null' || event ===undefined)
{
banner.goto(2);
eventplus = -1;
}
else if(event[0] === '+')
{
banner.goto(2);
eventplus = event.split('+')[1];
}
else
{
currenteventtime.setHours(event.split(':')[0]);
currenteventtime.setMinutes(event.split(':')[1]);
eventtime = currenteventtime;
}
}
Issue is with $scope.myeventtime
,which is eventtime
inside function, getting undefined. 问题是$scope.myeventtime
,它是函数内部的eventtime
,未定义。
HTML: HTML:
<timepicker class="timepicker" ng-model="myeventtime" hour-step="hstep" minute-step="mstep" show-meridian="ismeridian"></timepicker>
The time is not being set. 时间未设定。
You are changing the pointing value of a local variable eventtime
not the original scope variable. 您正在更改本地变量eventtime
的指针值,而不是原始范围变量。 Since this is a date object you can do that instead: 由于这是一个日期对象,因此您可以执行以下操作:
eventtime.setHours(event.split(':')[0]);
eventtime.setMinutes(event.split(':')[1]);
this will act upon the original scope param as setHours
and setMinutes
are methods of the original object. 这将对原始范围参数setHours
,因为setHours
和setMinutes
是原始对象的方法。
Edit : Just realized you are attempting to set both currenteventtime
and eventtime
to the same value. 编辑 :刚意识到您正在尝试将currenteventtime
和eventtime
设置为相同的值。 you would need to run setHours
and setMinutes
on both then 您将需要同时运行setHours
和setMinutes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.