你好我是 Angular JS 的初学者,当我开始创建模块和 Controller 时,我无法打印我的消息,下面是我的代码
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",[]);
Controller 也应该是,
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 - Uncaught Error : [$injector:modulerr] and Uncaught Error: [$injector:nomod],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40631972/