Having some difficulty passing a value from one function to another within an Angular controller.
I have an event:
onTimeRangeSelected: function (args) {
$scope.dayPilotCal.clearSelection();
$scope.createNewEventModalWindow(args);
},
The event calls the function:
$scope.createNewEventModalWindow = function(args)
{
console.log('create new event dialog');
$rootScope.newEvent.start = args.start.value;
console.log($rootScope.newEvent.start);
ngDialog.open({
......
});
}
Then, I handle the dialog confirm button click event:
<button
type="button"
class="ngdialog-button ngdialog-button-primary"
ng-click="btnCreateEventClicked()"
>Create</button>
And call the function:
$scope.btnCreateEventClicked = function(){
console.log('btn create event clicked');
ngDialog.close();
console.log($rootScope.newEvent.start);
};
My problem is that in the first case
console.log($rootScope.newEvent.start);
prints the real date to the console. However, in the second function console.log($rootScope.newEvent.start);
prints 'undefined'
to the console.
All the code resides in the same controller. At the beginning of the controller, I define my global variable $rootScope.newEvent={};
If anyone could assist me with this problem, it would be greatly appreciated. Thank you.