resultimo patel resultimo patel - 1 month ago 20
AngularJS Question

make alert call when checkbox is unchecked and button clicked

hello i am new in angular.js and i am currently finding a code to do alert call on button click. i have tried something. i have one checkbox one button and one label. i want to keep alert on button's on click. Here is my code.

<div ng-app="" ng-init="mySwitch=true">
<p>
<button ng-disabled="mySwitch" id="demo" type="button" onclick="javascript:alert1();">Click Me!</button>
</p>
<p>
<input type="checkbox" ng-model="mySwitch"/>Button
</p>
<p>
{{ mySwitch }}
</p>
</div> `


and here it is my jquery

alert1()
{
alert('hi');
}

Answer

It's quite simple:

<div ng-app="" ng-init="mySwitch=true">
<p>
<button ng-disabled="mySwitch" id="demo" type="button" onclick="document.getElementById('demo').innerHTML = alert('hi')">Click Me!</button>
</p>
<p>
<input type="checkbox" ng-model="mySwitch"/>Button
</p>
 <p>
     {{ mySwitch }}
 </p>
</div>