如何在输入文本框中放置默认值

How can I place the default value in the input text box

我有以下代码。我想将默认值分配给最初显示在框中的脚本变量。稍后该值必须根据用户在文本框中的输入进行更改。

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

我希望“20”和 "zigo" 最初显示在文本框中。我怎样才能更改我的代码?

您在 html 中缺少 ng-controller 并且控制器应该是,

 app.controller("test", function($scope){

不是

app.controller=("test", function($scope){

演示

  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>

检查下面的 link。您忘记在 <div>.

中提及您的测试控制器

Edited version of your code

 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>