错误:[$ controller:ctrlreg]未注册名为'classifiedsCtrl'的控制器

时间:2017-02-16 17:45:47

标签: javascript angularjs

新角度。如果没有控制器它运行良好,然后将ng-controller指令添加到html标记并打破插值。使用Angular 1.6。我错过了什么?

的index.html

<!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>

app.js

angular.module("ngClassifieds", []);

classifieds.ctr.js

(function() {
    "use strict"

    angular
        .module("ngClassifieds")
        .controller("classifiedsCtrl", function($scope) {

            $scope.name = "George Washington";
        });
    })();

1 个答案:

答案 0 :(得分:-2)

就像你宣布应用程序两次一样,试试这个:

app.js

var myApp = angular.module("ngClassifieds", []);

classifieds.ctr.js

myApp.controller("classifiedsCtrl", function($scope) {
      $scope.name = "George Washington";
   });