gpt4 book ai didi

javascript - Uncaught Error : [$injector:modulerr] and Uncaught Error: [$injector:nomod]

转载 作者:行者123 更新时间:2023-11-30 15:42:10 33 4
gpt4 key购买 nike

你好我是 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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com