Skip to content Skip to sidebar Skip to footer

Is It Possible To Use Ng-value And Ng-model At The Same Time?

Is it possible to use ng-value and ng-model at the same time? I find this code on W3school https://www.w3schools.com/angular/tryit.asp?filename=try_ng_ng-value I try to add ng-mode

Solution 1:

There is a mismatch between your variable names. You are using both showVar and myVar. Try this:

<div ng-app="myApp" ng-controller="myCtrl">
<input ng-value="myVar" ng-model="myVar">
{{myVar}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.myVar = "Hello World!";
});
</script>

Solution 2:

Yes you can use.check the angular documentation for more details ngValue angular


Solution 3:

Hi data will bind using ng-model .so $scope.myVar = "Hello World!"; its wrong. it would be your model name like $scope.showVar = "Hello World!";


Post a Comment for "Is It Possible To Use Ng-value And Ng-model At The Same Time?"