The beauty of Angular is that the state of your data must control what happens to your view.
In the case of the functions you are calling, it looks like what you want to use, perhaps ng-show / ng-hide / ng-if .
Angular Docs
<div class="elementYouWantToTarget" ng-show="expressionOrVariableThatEvaluatesToTrueOrFalseWhichWillEitherShowOrHideYourElementComingFromAnAngularControllerInThisElementsScope"> <stuff>...</stuff> </div>
And in your controller
angular.controller("myAwesomeExampleControllerExplainingAngular", ["$scope", controllerFn]); function controllerFn($scope) { $scope.expressionOrVariableThatEvaluatesToTrueOrFalseWhichWillEitherShowOrHideYourElementComingFromAnAngularControllerInThisElementsScope = true; }
EDIT: So, according to Amit (and if I understood correctly), he wants to show or hide this element based on the mouse down event. Once again, if we pay attention to the fact that we want to change the data in Angular to make changes to the state of the view, we can use the ng-mousedown directive and attach it to your element:
<div class="elementYouWantToTarget" ng-show="expressionOrVariableThatEvaluatesToTrueOrFalseWhichWillEitherShowOrHideYourElementComingFromAnAngularControllerInThisElementsScope" ng-mousedown="expressionLivingInYourControllerSomewhereThatIsCalledWhenTheMouseDownDeventFiresOnYourElement()" ng-mouseup="expressionDoingTheSameThingExceptForWhenTheMouseUpEventHappens()"> <stuff>...</stuff> </div>
And in your controller (PS. I assume that the element disappears on the mouse, otherwise you do not need the ng-mouseup directive or related functions).
angular.controller("myAwesomeExampleControllerExplainingAngular", ["$scope", controllerFn]); function controllerFn($scope) { $scope.expressionOrVariableThatEvaluatesToTrueOrFalseWhichWillEitherShowOrHideYourElementComingFromAnAngularControllerInThisElementsScope = false; $scope.expressionLivingInYourControllerSomewhereThatIsCalledWhenTheMouseDownDeventFiresOnYourElement = function reallyLongButShouldBeNamedStillFn($event) { //setting variable to true shows element based on ng-show $scope.expressionOrVariableThatEvaluatesToTrueOrFalseWhichWillEitherShowOrHideYourElementComingFromAnAngularControllerInThisElementsScope = true; } $scope.expressionDoingTheSameThingExceptForWhenTheMouseUpEventHappens() = nameAllYourFunctionsFn($event) { //setting variable to false hides element based on ng-show. $scope.expressionOrVariableThatEvaluatesToTrueOrFalseWhichWillEitherShowOrHideYourElementComingFromAnAngularControllerInThisElementsScope = false; } }
Sean larkin
source share