stereoPanda
stereoPanda

Reputation: 1

Ionic & Angular JS: trying to add item to list but list is not defined

I've checked various threads and tutorials, simply trying to add an item to an ionic list by clicking on a button. However, I'm not able to make it. I'm pretty sure that I'm the problem.. :)

Please find my code below. Assigning a date to newDate works fine, and the array groups works fine to create a list (via ng-repeat). The problem occurs when I'm trying to run the function addEntry via a button, no item is added to the list and I'm receiving "Error: groups is not defined" in the console log.

I hope that it's a simple declaration problem which can be solved by a one sentence answer... thanks in advance!!!

HTML Button:

<button class="button button-block button-balanced" ng-click="doRefresh()" ui-sref="menu.tagebucheintrag">
Send
</button>

In controller:

$scope.groups = [{name:'25.11.2016'},{name:'26.11.2016'},{name:'27.11.2016'},{name:'28.11.2016'}];

$scope.addEntry = function () {     
    console.log('Button pressed');
    var newDate = FromDate
    console.log(newDate);
    $scope.groups.push({ name: newDate });
    console.log(groups[0])
};

Upvotes: 0

Views: 147

Answers (1)

Ram_T
Ram_T

Reputation: 8484

On clicking button you are calling doRefresh() but there is no refresh function. You have to change ng-click="doRefresh()" to ng-click="addEntry()" to push the date if fromDate is works.

<button class="button button-block button-balanced" ng-click="addEntry()" ui-sref="menu.tagebucheintrag">
Send
</button>

Otherwise do this

$scope.groups = [{name:'25.11.2016'},{name:'26.11.2016'},{name:'27.11.2016'},{name:'28.11.2016'}];
$scope.addEntry= function(){
     $scope.newDate = new Date().getDate() + '.' + (new Date().getMonth()+1) + '.' + new Date().getFullYear();
     $scope.groups.push({ name: newDate });
}

Upvotes: 1

Related Questions