lundi 14 septembre 2015

how to use ng-show with checkboxes

I have tried all the solutions i could find but i am stuck. I have 2 checkboxes, HBO and Marvin. Marvin needs to show a div. HBO needs to show nothing. It works until I need to click the checkbox twice for it to show/hide. usually this would be a $apply() issue but that does not seem to be the case. I believe I am not updating the model correctly. I forgot to mention that the checkboxes need to reset to false when the other is true. plunker

 var ctrl = this;
    ctrl.showMeMarvin = function () {
        if (ctrl.show === true) {
            //$timeout(function () {
            ctrl.marvin = false;
            ctrl.show = false;
            ctrl.hbo = false;
            //})
        }
        else {
            //$timeout(function () {
            ctrl.marvin = true;
            ctrl.show = true;
            ctrl.hbo = false;
            //})
        }
    };

    ctrl.showMeHBO = function () {
        if (ctrl.show === true) {
            // $timeout(function () {
            ctrl.show = false;
            ctrl.hbo = true;
            ctrl.marvin = false;
            //})
        }
        else {
            //$timeout(function () {
            ctrl.marvin = false;
            ctrl.hbo = true;
            //})
        }
    };




Aucun commentaire:

Enregistrer un commentaire