输入值在angularJS中不可见 [英] Input value not visible in angularJS
本文介绍了输入值在angularJS中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此输入值应为"Paris",但不会显示.我的代码有什么问题?
This input value should be "Paris" but it does not display. What is wrong with my code?
(function(angular, undefined) {
var mon_app = angular.module('mon_app', []);
angular.module('mon_app').controller('monctrl', function($scope) {})
}(window.angular));
<!DOCTYPE html>
<html class="app" ng-app="mon_app">
<head lang="fr" class="app">
</head>
<body>
<div ng-controller="monctrl">
This input value is "Paris"
<input name="lieu" ng-model="lieu" type="text" value="Paris" />
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.js"></script>
</body>
推荐答案
您不能混合使用常规HTML(输入的 value
属性)和角度驱动的 ng-model 代码>.输入将始终显示
ng-model
中的值,此处为 lieu
,因此应使用Paris值对 $ scope.lieu
进行初始化.
You cannot mix regular HTML (the value
attribute of your input) and the angular-driven ng-model
. The input will always display the value of what's in ng-model
, here lieu
, hence you should iniialize $scope.lieu
with the Paris value.
(function(angular, undefined) {
var mon_app = angular.module('mon_app', []);
angular.module('mon_app').controller('monctrl', function($scope) {
$scope.lieu = "Paname";
})
}(window.angular));
<!DOCTYPE html>
<html class="app" ng-app="mon_app">
<head lang="fr" class="app">
</head>
<body>
<div ng-controller="monctrl">
This input value is "{{lieu}}"
<input name="lieu" ng-model="lieu" type="text"/>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.js"></script>
</body>
这篇关于输入值在angularJS中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文