gpt4 book ai didi

javascript - Angular 中的 [$injector :nomod], [$injector:modulerr] 错误

转载 作者:行者123 更新时间:2023-12-03 06:46:57 26 4
gpt4 key购买 nike

我对 Angular js 很陌生,以下是我的代码

<script type="text/javascript" src="node_modules/angular/angular.min.js"></script>

<script type="text/javascript">
(function(angular){

var testAngular = angular.module('testAngular');

testAngular.controller = ("name_controller", function($scope) {console.log("hello");
$scope.name = {
firstName: "null",
lastName: "null",
setName: function(fname, lname) {

if(fname.trim != "") {
this.firstName = fname;
}

if(lname.trim()!="") {
this.lastName = lname;
}
},
getName: function() {
var name_object = $scope.name;
return name_object.firstName+" "+name_object.lastName;
}
};
});
})(window.angular);
</script>

<div ng-app="testAngular" ng-controller="name_controller">
Enter first name: <input type="text" ng-model="name.firstName"><br><br>
Enter last name: <input type="text" ng-model="name.lastName"><br>
<br>
You are entering: {{ name.firstName }}
</div>

现在,当我尝试运行此代码时,我在控制台中收到 2 个错误,如下所示

[$injector:nomod]

 [$injector:modulerr]

知道为什么会发生这种情况吗?有些帖子说我需要包含路由模块,但我没有在代码中的任何位置使用路由。

最佳答案

尝试改变:

testAngular.controller = ("name_controller", function($scope) {

testAngular.controller("name_controller", function($scope) {

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

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