ng-click is not fired within a label (Angular1)

0

Good afternoon,

In my project, I have a component that is shared by different components. This component is called toggle-switch-input. This component serves to allow the filtering of some values in a list, and each item has a slider which, after its click, should have a slide effect. In your html (toggle-switch-input.html), I have the following code:

<label>
  <input
    type="checkbox"
    ng-click="vm.itemToggleSwitch(vm.choices.indexOf(choice))"
    ng-checked="!vm.isSelected(vm.choices.indexOf(choice))">
    
    <div class="slider round"></div>
</label>

And in your controller (toggle-switch-input.controller.js) I have the isSelected and itemToggleSwitch ). There are many pages that use this component without any problem, except for one of them. I've been doing some prints in the browser console, and when I click on the element I want (in this case on a button in slide format), it calls the isSelected function, but by some reason can not call the ng-click (itemToggleSwitch) function. However, on the other pages this occurs without any kind of problem: It does the slide by calling the isSelected and itemToggleSwitch functions.

Does anyone have any light? I'm around the code and I'm not seeing any possible solution. The strange thing is that this component can be shared perfectly by other components, except one.

The two functions present in the controller toggle-switch-input.controller.js:

this.isSelected = (index) => {
  if(this.ngModel.$modelValue.indexOf(this.choices[index]) === -1){
    return false;
  } else{
    return true;
  }
};

this.itemToggleSwitch = function (index) {

    var newList = angular.copy(this.ngModel.$modelValue);

    var itemIndex = newList.indexOf(this.choices[index]);

    if(itemIndex === -1){
        newList.push(this.choices[index]);
    } else {
        newList.splice(itemIndex, 1);
    }

    this.ngModel.$setViewValue(newList);
}.bind(this);

Thank you and a good day's continuation!

    
asked by anonymous 09.10.2017 / 19:06

0 answers