未被捕获的错误:[$ injector:modulerr]和未被捕获的错误:[$ injector:nomod]
问题描述:
嗨我是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>
感谢
答
您需要添加空的依赖
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>
谢谢ÿ ou,但无法得到你在代码中所做的所有更改。你能区分它吗?我得到了空注射器 –
@ManjulaD我已经在答案中提到,你可以扩大代码段并检查 – Sajeetharan
嘿,谢谢,我明白了.. :) –