Error on failure: [$ injector: modulerr] Failed to create myModule module

I am trying to display 3 variables, but getting errors in the console

here is the script.js code

var myApp = angular
    .module("myModule",[])
    .controller("myController", function ($scope) {
        var employee = {
            firstName: "Sunil"
            lastName: "Bhatraju"
            gender: "Male"
        };

        $scope.employee = employee;
    });

here is the demo.html code

<!doctype html>
<html ng-app="myModule">
<head>
    <script src="Scripts.js/script.js"></script>
    <script src="Scripts.js/angular.js"></script>
</head>
<body>
    <div ng-controller="myController">
<div>
    First Nmae: {{ employee.firstName }}
</div>
<div>
    Last Name : {{ employee.lastName }}
</div>
<div>
    Gender : {{ employee.gender }}
</div>
</div>

errors displayed on the console

1) Uncaught SyntaxError: Unexpected identifier

2) Missed error: [$ injector: modulerr] Failed to create myModule module because of: Error: [$ injector: nomod] Module 'myModule' is not available! You either mistakenly wrote the name of the module, or forgot to load it. If registering a module ensures that you specify the dependencies as the second argument.

here is an image of my webstrom project

+4
source share
2 answers

There are several errors

add commas to the end

var employee = {
        firstName: "Sunil",
        lastName: "Bhatraju",
        gender: "Male"
};

two add angular lib first

<script src="Scripts.js/angular.js"></script>
<script src="Scripts.js/script.js"></script>
+1

angular.js, script.js

<script src="Scripts.js/angular.js"></script>
<script src="Scripts.js/script.js"></script>

, ,

 var employee = {
                firstName: "Sunil",
                lastName: "Bhatraju",
                gender: "Male"
            };

DEMO

var myApp = angular
    .module("myModule",[])
    .controller("myController", function ($scope) {
        var employee = {
            firstName: "Sunil",
            lastName: "Bhatraju",
            gender: "Male"
        };

        $scope.employee = employee;
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myModule">
    <div ng-controller="myController">
<div>
    First Nmae: {{ employee.firstName }}
</div>
<div>
    Last Name : {{ employee.lastName }}
</div>
<div>
    Gender : {{ employee.gender }}
</div>
</div>
Hide result
+3

Source: https://habr.com/ru/post/1685286/


All Articles