输入值在angularJS中不可见

时间:2015-01-21 21:04:13

标签: angularjs input

此输入值应为“Paris”但不显示。 我的代码出了什么问题?

(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>

1 个答案:

答案 0 :(得分:6)

您不能混合常规HTML(输入的value属性)和角度驱动的ng-model。输入将始终显示ng-modellieu中的内容的值,因此您应该使用巴黎值初始化$scope.lieu

&#13;
&#13;
(function(angular, undefined) {
  var mon_app = angular.module('mon_app', []);
  angular.module('mon_app').controller('monctrl', function($scope) {
    $scope.lieu = "Paname";
  })
}(window.angular));
&#13;
<!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>
&#13;
&#13;
&#13;