Javascript 错误:[$controller:ctrlreg]名称为';classifiedsCtrl';没有注册
新的角度。让它在没有控制器的情况下运行良好,然后将ng控制器指令添加到html标记并中断插值。使用角度1.6。我错过了什么 index.htmlJavascript 错误:[$controller:ctrlreg]名称为';classifiedsCtrl';没有注册,javascript,angularjs,Javascript,Angularjs,新的角度。让它在没有控制器的情况下运行良好,然后将ng控制器指令添加到html标记并中断插值。使用角度1.6。我错过了什么 index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ngClassifieds</title> </head> <body ng-app="ngClassifi
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ngClassifieds</title>
</head>
<body ng-app="ngClassifieds" ng-controller="classifiedsCtrl">
<h1>{{ name }}</h1>
<!-- Scripts -->
<script src="node_modules/angular/angular.js"></script>
<script src="scripts/app.js"></script>
<script src="components/classifieds.ctr.js"></script>
</body>
</html>
classifieds.ctr.js
angular.module("ngClassifieds", []);
(function() {
"use strict"
angular
.module("ngClassifieds")
.controller("classifiedsCtrl", function($scope) {
$scope.name = "George Washington";
});
})();
这就像您要声明应用程序两次,请尝试以下操作: app.js
var myApp = angular.module("ngClassifieds", []);
classifieds.ctr.js
myApp.controller("classifiedsCtrl", function($scope) {
$scope.name = "George Washington";
});
路径是否正确?可能是..检查您的ctrl文件路径检查文件路径并不是问题所在。谢谢though@user3911617似乎路径有问题。我刚刚创建了一个plnker,在工作中,没有。
angular.module(“ngClassifieds”)
是一个getter,而不是setter,当不存在第二个参数时,您的方法需要公开一个不需要的全局变量。看见