[英]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? 是否可以同时使用ng-value和ng-model? 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. 我在W3school上找到了这段代码https://www.w3schools.com/angular/tryit.asp?filename=try_ng_ng-value我尝试在输入文本中添加
ng-model="showVar"
在其中添加{{showVar}}
html。 but when I run the html. 但是当我运行的HTML。 the
{{showVar}}
did not show the Hello World!!!
{{showVar}}
没有显示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>
There is a mismatch between your variable names. 您的变量名之间不匹配。 You are using both
showVar
and myVar
. 您正在同时使用
showVar
和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>
是的,您可以使用。有关更多信息,请检查角度文档。ngValue angular
Hi data will bind using ng-model .so $scope.myVar = "Hello World!";
嗨,数据将使用ng-model绑定。so
$scope.myVar = "Hello World!";
its wrong. 这是不对的。 it would be your model name like
$scope.showVar = "Hello World!";
这将是您的模型名称,例如
$scope.showVar = "Hello World!";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.