Skip to content

on server deployment doesn't show model value #41

@firatkucuk

Description

@firatkucuk

My web app has tons of controller and JS stuff included. So checkbox always show false state. But when I give delay for initialization it works well.

function initializeSwitch() {
  $timeout(function() {
    // Remove any old switcher
    if (switcher) {
      angular.element(switcher.switcher).remove();
    }
    // (re)create switcher to reflect latest state of the checkbox element
    switcher = new $window.Switchery(elem[0], options);
    var element = switcher.element;
    element.checked = scope.initValue;
    if (attrs.disabled) {
      switcher.disable();
    }

    switcher.setPosition(false);
    element.addEventListener('change',function(evt) {
        scope.$apply(function() {
            ngModel.$setViewValue(element.checked);
        })
    });
    scope.$watch('initValue', function(newValue, oldValue) {
        switcher.setPosition(false);
    });
  }, 200); // <-- changed value 0 to 200
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions