angularjs scope variable change onclick for conditional div
angularjs
Solution
I'm not exactly sure what you are trying to do, but Angular provides `ng-click`, so you should not have to bind to `$(document).on('click')`.
I'd suggest a simpler approach for conditional show:
<div ng-show="desc" id="description" class="text-muted" style="padding-top:5px;padding-left:10px;padding-right:10px;color:#2E2E2E;font-size:11px;">{{myapp.value|truncate}}<span><a id="showmore" ng-click="desc = true" href="#">more</a></span>
</div>
<div ng-show="!desc" id="description" class="text-muted" style="padding-top:5px;padding-left:10px;padding-right:10px;color:#2E2E2E;font-size:11px;">{{myapp.value}}<span><a id="showless" ng-click="desc = false" href="#">less</a></span>
</div>
The above uses `ng-click` to set the value of `desc`. Therefore, you don't need any other logic in the controller to toggle the `divs`.
Problem
i have two divs i want to show them conditionally with onclick event . my-angular-app.js ``` $(document).on('click', '#showless', function(el) { var appElement = document.querySelector('[ng-app=myapp]'); var $scope = angular.element(appElement).scope(); $scope.$apply(function() { $scope.value = false; }); }); $(document).on('click', '#showmore', function(el) { var appElement = document.querySelector('[ng-app=myapp]'); var $scope = angular.element(appElement).scope(); $scope.$apply(function() { $scope.value = true; }); }); ``` and my div of myapp (myapp.html) ``` <div ng-show="desc" id="description" class="text-muted" style="padding-top:5px;padding-left:10px;padding-right:10px;color:#2E2E2E;font-size:11px;">{{myapp.value|truncate}}<span><a id="showmore" href="">more</a></span> </div> <div ng-show="!desc" id="description" class="text-muted" style="padding-top:5px;padding-left:10px;padding-right:10px;color:#2E2E2E;font-size:11px;">{{myapp.value}}<span><a id="showless" href="">less</a></span> </div> ``` (truncate is a filter i wrote which works fine .)