HTML input element is have properties as following ng-model and ng-value as declare dynamic change the event fire on button click. A button ng-value is change on when event is fire, This logic is apply into ng-model component value is replace the ng-value block.
Sample HTML Code:
<div ng-app="BtnApp">
<div ng-controller="BtnCtrl">
Do you want Car?
<input type="button" ng-model="youWantCar" ng-value="youWantCar" ng-click="changeStatus()"/>
</div>
</div>
AngularJS:
var app = angular.module('BtnApp', []);
app.controller('BtnCtrl',function($scope){
$scope.youWantCar = "No";
$scope.changeStatus = function(){
if($scope.youWantCar == "No")
$scope.youWantCar = "Yes";
else
$scope.youWantCar = "No";
};
});
Result:
Demo
Sample HTML Code:
<div ng-app="BtnApp">
<div ng-controller="BtnCtrl">
Do you want Car?
<input type="button" ng-model="youWantCar" ng-value="youWantCar" ng-click="changeStatus()"/>
</div>
</div>
AngularJS:
var app = angular.module('BtnApp', []);
app.controller('BtnCtrl',function($scope){
$scope.youWantCar = "No";
$scope.changeStatus = function(){
if($scope.youWantCar == "No")
$scope.youWantCar = "Yes";
else
$scope.youWantCar = "No";
};
});
Result:
Demo
Comments
Post a Comment