ANGULAR NG-SHOW AND CHANGE TEXT FIELD TO INPUT FIELD

Posted on

Example code in Angular JS to change the text Heading to input text field without losing 2-way data binding.

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<h1 ng-dblclick="change()" ng-if="!myv">{{carname}}</h1>
<h1 ng-show="myv"><input type="text" ng-model="carname"><button ng-click="done()">Done</button></h1>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.carname = "Volvo";
$scope.change = function() {
$scope.myv = true;
};

$scope.done = function(){
$scope.myv = false;
}
});
</script>

<p>The property "carname" was made in the controller, and can be referred to in the view by using the {{ }} brackets.</p>

</body>
</html>
Example
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *