javascript - AngularJS 启动器卡住了

标签 javascript html angularjs

只需要解释为什么这不起作用?我试图从教程点开始遵循教程。第一个和第二个模型工作正常。但不适用于第三种型号。有人可以向我解释为什么它不起作用吗?提前致谢。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>

..........

<body ng-app="mainApp" ng-controller="machineController">

  <input type="text" ng-model="anyText.first" placeholder="any text here" />
  <input type="text" ng-model="anyText.second" placeholder="any text here" />

  <span>{{ anyText.third() }}</span>

  <script>
    var app = angular.module("mainApp", []);

    app.controller('machineController', function($scope) {
      $scope.anyText = {
        first: "This is first default text",
        second: "This is second default text",

        third: function() {
          $object = $scope.anyText;
          var newtext = anyText.first + " ::: " + anyText.second;
          return newtext;
        }

      };
    });
  </script>

</body>

最佳答案

您必须替换此行

var newtext = anyText.first + ":::"+ anyText.second;

var newtext = $object.first + " ::: " + $object.second;

as anyText 变量未定义

<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>


<body ng-app="mainApp" ng-controller="machineController">

 <input type="text" ng-model="anyText.first" placeholder="any text here"/>
 <input type="text" ng-model="anyText.second" placeholder="any text here"/>

 <span>{{ anyText.third() }}</span>

 <script>
  var app = angular.module("mainApp", []);

  app.controller('machineController',function($scope){
      $scope.anyText = {
          first: "This is first default text",
          second: "This is second default text",

          third: function(){
              $object = $scope.anyText;
              var newtext = $object.first + " ::: " + $object.second;
              return newtext;
          }

      };
  });
</script>

</body>

关于javascript - AngularJS 启动器卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46597724/

相关文章:

javascript - 在加载 Jqgrid 之前和加载网格之后我应该在哪里使用方法来阻止屏幕?

html - 如何删除具有不同位置属性的两个标签之间的空格?

javascript - 如何使用 Jasmine 监视匿名函数

javascript - Angularjs 读取模板中对象的值

javascript - 将 JavaScript 添加到 w2ui 面板

css - Angular 中链接的多次点击功能

javascript - 有没有类似于Chrome的inspect元素功能的HTML编辑器?

javascript - 关闭模态后页面变暗无法上下滚动

javascript - 如何解决 React Hook 关闭问题?

android - 使用 html/css3 和 WebView 将图像缩放到屏幕上……在图像加载之前出现白屏