0

AngularJS 初学者在这里。写一个简单的页面来学习。它所做的只是接受用户输入,然后对其应用操作(*10)并将其显示在页面中。我不知道为什么这不起作用,没有显示 {{funding.needed}} 的值....有什么想法吗?

  <html ng-app>
<head>
  <title>Learning</title>
</head>
<!--View - user input to collect a value and then apply logic to it-->
    <div>
    <form ng-controller="StartUpController">
        Starting: <input ng-change="computeNeeded()" 
                         ng-model="funding.startingEstimate">
         Recommendation: {{funding.needed}}
    </form>

</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script>

  //startup controller to intiialize variable and computeNeeded function to apply logic
  function StartUpController($scope) {
      $scope.funding = {startingEstimate: 0};  
      };

    $scope.computeNeeded = function(){
     $scope.funding.needed = $scope.funding.startingEstimate * 10;   
    };
</script>
</body>
</html>
4

1 回答 1

0

computeNeeded 函数需要包含在控制器中,以便它可以访问 $scope 对象:

<script>

  //startup controller to intiialize variable and computeNeeded function to apply logic
  function StartUpController($scope) {
      $scope.funding = {startingEstimate: 0};  


    $scope.computeNeeded = function(){
     $scope.funding.needed = $scope.funding.startingEstimate * 10;   
    };
 };
</script>
于 2014-09-16T19:11:58.610 回答