Code Monkey home page Code Monkey logo

Comments (7)

millenjo avatar millenjo commented on June 26, 2024 1

The problem is most likely that the ng-model value is evaluated as undefined when the template is rendered and when the controller sets available to false the directive interprets it as a model change, which it strictly speaking is even though one might argue that a ng-model change from undefined->true/false should not trigger a model change since it's almost always just an init case.

The problem can be solved by adding an ng if like this

ng-if="model.available !== undefined"

to the bs-switch input or a wrapping element, ng-show will not work since that wont stop the template from rendering the input element.

from angular-bootstrap-switch.

pradt avatar pradt commented on June 26, 2024

I tried to debug this and noticed that the switchChange() is being called upon a model change. I'm wondering why this would need to call the switchChange function if a model is changed ?

          controller.$render = function () {
            initMaybe();
            var newValue = controller.$modelValue;
            if (newValue !== undefined && newValue !== null) {
              element.bootstrapSwitch('state', newValue === getTrueValue(), true);
            } else {
              element.bootstrapSwitch('indeterminate', true, true);
              controller.$setViewValue(undefined);
            }
            switchChange();
          };

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on June 26, 2024

What do you mean? switch-change is called every time the model changes. If you want to listen to view changes, please use ng-change.

from angular-bootstrap-switch.

pradt avatar pradt commented on June 26, 2024

ok I'll try that, what's switch-change for ?

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on June 26, 2024

It's for model changes.

from angular-bootstrap-switch.

Firzenizer avatar Firzenizer commented on June 26, 2024

I also ran into this and I find it unexpected behaviour. In my app an undefined settings item gets initialized and this is triggering switch-change. Using ng-change now. It works as I wanted it to work.

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on June 26, 2024

Please re-open if you still have this issue.

from angular-bootstrap-switch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.