我有以下代码。我想将最初显示在脚本变量中的默认值分配给框中。之后,该值必须根据用户在文本框中的输入进行更改。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Hello app </title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.js"></script>
</head>
<body>
<div ng-app="testapp">
<p> Enter your name: <input type="text" ng-model="name"></p>
<p> Enter your age here: <input type="text" ng-model="age"> </p>
<ol>
<li> My Name is {{ name }} </li>
<li>I am {{ age}} years old </li>
</ol>
<script>
var app = angular.module("testapp",[]);
app.controller=("test", function($scope){
$scope.age = "20"
$scope.name = "zigo"
});
</script>
</div>
</body>
</html>
我想&#34; 20&#34;和&#34; zigo&#34;最初显示在文本框中。我该如何更改我的代码?
答案 0 :(得分:3)
您在html中缺少 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/afterglowplayer@1/dist/afterglow.min.js"></script>
<video class="afterglow" id="myvideo" width="640" height="480" src="https://www.srv33.convertinmp4.com/download.php?v=LDD1HwKwTg9TeQc1w9q47JAq6dyuqV3v" data-skin="dark"></video>
,控制器应该是,
ng-controller
不会强>
app.controller("test", function($scope){
<强>样本强>
app.controller=("test", function($scope){
&#13;
var app = angular.module("testapp",[]);
app.controller("test", function($scope){
$scope.age = "20"
$scope.name = "zigo"
});
&#13;
答案 1 :(得分:0)
检查以下链接。您忘了在<div>
中提及您的测试控制器。
答案 2 :(得分:0)
var app = angular.module("testapp",[]);
app.controller("test", function($scope){
$scope.age = "20"
$scope.name = "zigo"
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Hello app </title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.js"></script>
</head>
<body>
<div ng-app="testapp" ng-controller="test">
<p> Enter your name: <input type="text" ng-model="name"></p>
<p> Enter your age here: <input type="text" ng-model="age"> </p>
<ol>
<li> My Name is {{ name }} </li>
<li>I am {{ age}} years old </li>
</ol>
</div>
</body>
</html>