Disable User Behavior


#1

Hello,
I’m having trouble uploading an object to localstorage. I’ve created a button that should write the event that I’m accessing in ng-repeat here.
<ion-list> <ion-item class="animate-repeat" ng-repeat="event in events track by $index"> <div class="card card-wrapper" on-tap="desc = !desc"> <div class="item item-text-wrap" > <button style="float:right" ng-click="$scope.setEvents('event', event)">LIKE ME!!!</button> </div>

using this controller `app.controller(‘MainController’,
function MainController($scope, $ionicModal, $localStorage){

    $ionicModal.fromTemplateUrl('../app/LikedEvents.html', {
        scope: $scope,
        animation: 'slide-in-up'
    }).then(function(modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function() {
        $scope.modal.show();
    };
    $scope.closeModal = function() {
        $scope.modal.hide();
    };
    //Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function() {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function() {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function() {
        // Execute action
    });
    $scope.setEvents = function(key, value){
        console.log("I was clicked.");
        $localStorage.setObject(key, value);
    };

    $scope.getSavedEvents = function(key){
        $localStorage.getObject(key);
    }`

and this service app.factory('$localStorage', ['$window', function($window) { return { set: function(key, value) { $window.localStorage[key] = value; }, get: function(key, defaultValue) { return $window.localStorage[key] || defaultValue; }, setObject: function(key, value) { $window.localStorage[key] = JSON.stringify(value); }, getObject: function(key) { return JSON.parse($window.localStorage[key] || '{}'); } } }]);

but when I try to click the button, nothing happens. There are no errors, but the event doesn’t fire and nothing gets set. I noticed that there is a disable user behavior that is attached to the button, but I’m not sure how to go about fixing this. Anyone else encounter this?


#2

I think this is the cause of the problem.
In your template change this:
ng-click="$scope.setEvents('event', event)"
into this:
ng-click="setEvents('event', event)"


#3

Thank you so much. That worked!