2016-01-24 369 views
0

當用戶在文本框{{student.fullName()}}上輸入文本時應該更新。但是這不起作用。任何幫助?AngularJS控制器未顯示結果

示例應用程序

結果
<div ng-app = "mainApp" ng-controller = "studentController"> 
    Enter first name: <input type= "text" ng-model = "student.firstName"><br/><br/> 
    Enter last name: <input type= "text" ng-model = "student.lastName"><br/><br/> 

    You are entering: {{student.fullName()}} 
</div> 
<script> 
    var mainApp = angular.module("mainApp", []); 

    mainApp.Controller('studentController', function($scope){ 
     $scope.student = { 
      firstName: "Mahesh", 
      lastName: "Parashar", 

      fullName: function() { 
       var studentObject; 
       studentObject = $scope.student; 
       return studentObject.firstName+ " " + studentObject.lastName; 
      } 
     }; 
    }); 
</script> 

截圖:

enter image description here

+0

你正在使用哪個角度js版本? –

+0

區分大小寫錯誤。將控制器定義中的C更改爲c並嘗試 – Thangadurai

+0

儘管原因已發佈在響應中,但請注意,如果事情不起作用,請先檢查瀏覽器的控制檯。你會看到類似「Uncaught TypeError:mainApp.Controller不是一個函數」。 –

回答