admin管理员组

文章数量:1325236

The markup

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Angular I</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="author" href="humans.txt">
</head>
<body ng-app="app">

    <section ng-controller="mainCtrl">
      <h1>My App</h1>
      <p>{{name}}</p>
    </section>

    <script src=".js/1.5.0-beta.1/angular.min.js"></script>
    <script src=".js/1.5.0-beta.1/angular-route.min.js"></script>
    <script src=".js/1.5.0-beta.1/angular-animate.min.js"></script>
    <script src=".js/1.5.0-beta.1/angular-resource.min.js"></script>

    <script src="script.js"></script>
</body>
</html>

The script.js

var app = angular.module('friendsList', []);

app.controller('mainCtrl', function($scope) {
    $scope.name = "Leon Gaban";
})

I'm including angular.min, angular-route and even angular-resource and animate...

The markup

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Angular I</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="author" href="humans.txt">
</head>
<body ng-app="app">

    <section ng-controller="mainCtrl">
      <h1>My App</h1>
      <p>{{name}}</p>
    </section>

    <script src="https://cdnjs.cloudflare./ajax/libs/angular.js/1.5.0-beta.1/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare./ajax/libs/angular.js/1.5.0-beta.1/angular-route.min.js"></script>
    <script src="https://cdnjs.cloudflare./ajax/libs/angular.js/1.5.0-beta.1/angular-animate.min.js"></script>
    <script src="https://cdnjs.cloudflare./ajax/libs/angular.js/1.5.0-beta.1/angular-resource.min.js"></script>

    <script src="script.js"></script>
</body>
</html>

The script.js

var app = angular.module('friendsList', []);

app.controller('mainCtrl', function($scope) {
    $scope.name = "Leon Gaban";
})

I'm including angular.min, angular-route and even angular-resource and animate...

Share Improve this question edited Nov 1, 2015 at 22:52 Pankaj Parkar 136k23 gold badges240 silver badges303 bronze badges asked Nov 1, 2015 at 22:44 Leon GabanLeon Gaban 39.1k122 gold badges349 silver badges550 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You had wrong ng-app module, it should be ng-app="friendsList" instead of app.

The error is not due to angular versions, it is because you are injecting wrong dependency in your app mdoule. Simply you can not inject mainCtrl inside your module as its controller mainCtrl which you are going to register with your module.

var app = angular.module('friendsList', []);

Also you should have ng-controller="mainCtrl" on html.

<section ng-controller="mainCtrl">

</section>

本文标签: javascriptWhy am I getting the Angular injectormodulerr error here Using 15 betaStack Overflow