Dynamically add switch in ionic corner

I am trying to add a dynamic switch in ionic but it doesn't work. please help me.

if (maxScore==1){
angular.element(document.getElementById(objItem)).html(objItem + '<div> <ion-toggle ng-change="pushNotificationChange(this)"></ion-toggle></div></div>');   
}

      

Thanks in advance.

+3


source to share


1 answer


You cannot dynamically add to HTML with angular code.

To make it work, you need to compile it using the $ compile dependency

If you want to get around this, you just add your google code to your HTML with the condition



<div ng-if="maxScore===1"> <ion-toggle ng-change="pushNotificationChange(this)"></ion-toggle></div></div>
      

Run codeHide result


to your controller, just change your code which instanciate maxScore to $ scope.maxScore

+1


source







All Articles