angularjs - Transcluded input ng-model does not update scope variable passed to directive -


i have directive complicated label tag transcludes input element , takes input box's ng-model parameter.

<div switch model="testobject.switch">     <input type="checkbox" ng-model="$parent.testobject.switch"> </div> 

prior upgrading angular 1.4, clicking on directive updated ng-model , triggered watch inside directive.

now, clicking on directive still affects input box, value inside directive unaffected.

i appreciate insight caused change , how fix it.

fiddle

i have updated fiddle working code. if require ngmodel in directive , watch $modelvalue, able behavior looking for.

html:

<div switch ng-model="testobject.switch"> 

directive:

 booleanswitchmodule.directive('switch', [function () {   return {     scope: {},     require: "?^ngmodel",     link: function (scope, elem, attr, ngmodel) {         var timeschanged = 0;                     scope.$watch(function() {return ngmodel.$modelvalue; }, function (val) {              if (val != undefined) {                 alert("model changed " + ++timeschanged + " times");                  scope.switchposition = scope.model;             }         });       },     restrict: 'ea',     replace: true,     transclude: true,     template: '<label class="switch">' +         'directive scope model: {{ngmodel}}' +         '<span ng-transclude></span>' +         '</label>',   } }]); 

here updated fiddle: https://jsfiddle.net/62911kx5/3/


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -