2016-11-16 445 views
1

嗨我是Angular JS的初學者,當我開始創建模塊和控制器時,無法打印我的消息,下面是我的代碼

var myModule = angular.module("myFirst"); 
 

 
myModule.controller = ("cont", function($scope){ 
 
$scope.message = "Hi This is my first angular JS Learn "; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<!DOCTYPE html> 
 
<html ng-app="myFirst"> 
 
<head> 
 
<title>This is Angular JS tutorial</title> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> 
 

 
\t </head> 
 
<body> 
 
<div ng-controller="cont"> 
 
{{message}} 
 
</div> 
 

 
</body> 
 
</html>
任何一個可以解釋,是什麼問題造成的?

感謝

回答

2

您需要添加空的依賴

var myModule = angular.module("myFirst",[]); 

而且控制器應,

myModule.controller("cont", function($scope){ 
    $scope.message = "Hi This is my first angular JS Learn "; 
}); 

var myModule = angular.module("myFirst",[]); 
 

 
myModule.controller("cont", function($scope){ 
 
$scope.message = "Hi This is my first angular JS Learn "; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<!DOCTYPE html> 
 
<html ng-app="myFirst"> 
 
<head> 
 
<title>This is Angular JS tutorial</title> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> 
 

 
\t </head> 
 
<body> 
 
<div ng-controller="cont"> 
 
{{message}} 
 
</div> 
 

 
</body> 
 
</html>

+0

謝謝ÿ ou,但無法得到你在代碼中所做的所有更改。你能區分它嗎?我得到了空注射器 –

+0

@ManjulaD我已經在答案中提到,你可以擴大代碼段並檢查 – Sajeetharan

+0

嘿,謝謝,我明白了.. :) –

相關問題