Reputation: 257
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-model="showVar"
on the input text and add {{showVar}}
on the html.
but when I run the html. the {{showVar}}
did not show the Hello World!!!
....., any idea??Thx....
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<input ng-value="myVar" ng-model="showVar">
{{showVar}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.myVar = "Hello World!";
});
</script>
Upvotes: 0
Views: 1996
Reputation: 308
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!";
Upvotes: 0
Reputation: 134
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>
Upvotes: 1
Reputation: 2719
Yes you can use.check the angular documentation for more details ngValue angular
Upvotes: 0