嗨,我是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>

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

</body>
</html>




谁能解释一下,是什么原因造成的?

谢谢

最佳答案

您需要添加空的依赖项

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>

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

</body>
</html>

关于javascript - 未捕获的错误:[$ injector:modulerr]和未捕获的错误:[$ injector:nomod],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40631972/

10-12 15:46