I have a modal that uses ng-show="prefs" to determine visibility.
My desire is to use the close button in the modal to set $scope.prefs to false and to use an anchor tag to set the value to true. However, all I can find on google uses a checkbox rather than anchor tags.
Is there a way to use ng-click to set a variable to false?
We can add ng-click event conditionally without using disabled class.
The $ in AngularJs is a built-in object.It contains application data and methods.
Another significant difference between ng-click and onclick is the execution context. Code inside an onclick attribute executes against the global window object, while an expression inside of ng-click executes against a specific scope object, typically the scope object representing the model for the current controller.
For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.
Just do:
ng-click="prefs = false"
While @tymeJV gave a correct answer, the way to do this to be inline with angular would be:
ng-click="hidePrefs()"
and then in your controller:
$scope.hidePrefs = function() {
$scope.prefs = false;
}
You can use some thing like this
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body>
<div ng-app="" ng-init="btn1=false" ng-init="btn2=false">
<p>
<input type="submit" ng-disabled="btn1||btn2" ng-click="btn1=true" ng-model="btn1" />
</p>
<p>
<button ng-disabled="btn1||btn2" ng-model="btn2" ng-click="btn2=true">Click Me!</button>
</p>
</div>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With