Search code examples
angularjsangularjs-directiveangularjs-scope

Angular directive data binding not working inside ng-show


This is the example jsfiddle. I'm trying to ng-model the value on click of some thing. but this value is not updating in directive.I tried with $scope.$watch also . I'm sorry for poor english and newbie to angularjs.

    <div ng-click=show()>show directive</div>
<div ng-show="afterSomeTime">
<div class="star-rating" star-rating rating-value="rating"

 data-max="10" on-rating-selected="rateFunction(rating)"></div>sdsadasdasd</div>

here i was trying to trigger directive after some click event but i was not able to achieve.check out that example js fiddle link


Solution

  • Start from line 43

    scope.$watch('ratingValue',
        function(oldVal, newVal) { //<-this is where you did wrong
            if (newVal) {
                updateStars();
            }
        }
    );
    

    Just swap oldVal and newVal, you should now make it work I believe.