简体   繁体   English

由于实例化模块angularApp失败

[英]Failed to instantiate module angularApp due to

I have this bug when I work authentification between angular js and symfony , I have bug in front end (angular js) : 当我在angular js和symfony之间进行身份验证时出现此bug,前端(angular js)中有bug:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.6.5/ $injector/modulerr?p0=angularApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.6.5%2F%24injector%2Fmodulerr%3Fp0%3Drestangular%26p1%3DTypeError%253A%2520Cannot%2520read%2520property%2520'isUndefined'%2520of%2520undefined%250A%2520%2520%2520%2520at%2520Object.Configurer.init%2520(http%253A%252F%252Flocalhost%252Ftestauthenti%252Fnode_modules%252Frestangular%252Fdist%252Frestangular.js%253A42%253A29)%250A%2520%2520%2520%2520at%2520new%2520%253Canonymous%253E%2520(http%253A%252F%252Flocalhost%252Ftestauthenti%252Fnode_modules%252Frestangular%252Fdist%252Frestangular.js%253A812%253A16)%250A%2520%2520%2520%2520at%2520Object.instantiate%2520(https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A44%253A458)%250A%2520%2520%2520%2520at%2520c%2520(https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fan 未捕获的错误:[$ injector:modulerr] http://errors.angularjs.org/1.6.5/ $ injector / modulerr?p0 = angularApp&p1 = Error%3A%20%5 %% B%24injector%3Amodulerr%5D%20http%3A% 2F%2Ferrors.angularjs.org%2F1.6.5%2F%24injector%2Fmodulerr%3Fp0%3Drestangular%26P1%3DTypeError%253A%2520Cannot%2520read%2520property%2520'isUndefined'%2520of%2520undefined%250A%2520%2520%2520 %2520at%2520Object.Configurer.init%2520(HTTP%253A%252F%252Flocalhost%252Ftestauthenti%252Fnode_modules%252Frestangular%252Fdist%252Frestangular.js%253A42%253A29)%250A%2520%2520%2520%2520at%2520new%2520% 253Canonymous%253E%2520(HTTP%253A%252F%252Flocalhost%252Ftestauthenti%252Fnode_modules%252Frestangular%252Fdist%252Frestangular.js%253A812%253A16)%250A%2520%2520%2520%2520at%2520Object.instantiate%2520(HTTPS%253A %252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A44%253A458)%250A%2520%2520%2520%2520at%2520C%2520(HTTPS%253A% 252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fan gular.min.js%253A41%253A370)%250A%2520%2520%2520%2520at%2520Object.provider%2520(https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A41%253A312)%250A%2520%2520%2520%2520at%2520d%2520(https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A42%253A237)%250A%2520%2520%2520%2520at%2520https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A42%253A358%250A%2520%2520%2520%2520at%2520p%2520(https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A8%253A7)%250A%2520%2520%2520%2520at%2520g%2520(https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A42%253A138)%250A%2520%2520%2520%2520at%2520https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A42%253A322%0A%20%20%20%20at%20https%3A%2F%2Fc gular.min.js%253A41%253A370)%250A%2520%2520%2520%2520at%2520Object.provider%2520(HTTPS%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5 %252Fangular.min.js%253A41%253A312)%250A%2520%2520%2520%2520at%2520D%2520(HTTPS%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5% 252Fangular.min.js%253A42%253A237)%250A%2520%2520%2520%2520at%2520https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js %253A42%253A358%250A%2520%2520%2520%2520at%2520p%2520(HTTPS%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A8 %253A7)%250A%2520%2520%2520%2520at%2520克%2520(HTTPS%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A42% 253A138)%250A%2520%2520%2520%2520at%2520https%253A%252F%252Fcdnjs.cloudflare.com%252Fajax%252Flibs%252Fangular.js%252F1.6.5%252Fangular.min.js%253A42%253A322%0A%20 %20%20%20原子%20https%3A%2F%2FC dnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A7%3A76%0A%20%20%20%20at%20https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A43%3A70%0A%20%20%20%20at%20p%20(https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A8%3A7)%0A%20%20%20%20at%20g%20(https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A42%3A138)%0A%20%20%20%20at%20https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A42%3A322%0A%20%20%20%20at%20p%20(https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A8%3A7)%0A%20%20%20%20at%20g%20(https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A42%3A138)%0A%20%20%20%20at%20gb%20(https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A46%3A251)%0A%20%20%20%20at%20c%20(https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fa dnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A7%3A76%0A%20%20%20%20原子%20https%3A%2F%2Fcdnjs.cloudflare.com% 2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A43 3A70%%0A%20%20%20%20原子%20P%20(HTTPS%3A%2F%2Fcdnjs.cloudflare.com%2Fajax% 2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A8%3A7)%0A%20%20%20%20原子%20克%20(HTTPS%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs %2Fangular.js%2F1.6.5%2Fangular.min.js%3A42%3A138)%0A%20%20%20%20原子%20https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js% 2F1.6.5%2Fangular.min.js%3A42%3A322%0A%20%20%20%20原子%20P%20(HTTPS%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1。 6.5%2Fangular.min.js%3A8%3A7)%0A%20%20%20%20原子%20克%20(HTTPS%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5 %2Fangular.min.js%3A42%3A138)%0A%20%20%20%20原子%20GB%20(HTTPS%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5% 2Fangular.min.js%3A46%3A251)%0A%20%20%20%20原子%20c的20%(HTTPS%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2FA ngular.js%2F1.6.5%2Fangular.min.js%3A22%3A19)%0A%20%20%20%20at%20Uc%20(https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.6.5%2Fangular.min.js%3A22%3A332) ngular.js%2F1.6.5%2Fangular.min.js%3A22 3A19%)%0A%20%20%20%20原子%20UC%20(HTTPS%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fangular的.js%2F1.6.5%2Fangular.min.js%3A22%3A332)

and this is link error: 这是链接错误:

https://docs.angularjs.org/error/ $injector/unpr?p0=RestangularProvider%20%3C-%20Restangular%20%3C-%20MainCtrl https://docs.angularjs.org/error/ $ injector / unpr?p0 = RestangularProvider%20%3C-%20Restangular%20%3C-%20MainCtrl

code index.html: 代码index.html:

<!doctype html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">
        <!-- <link rel="stylesheet" href="styles/main.css"> -->
      </head>
      <body ng-app="angularApp">
        <div class="container">
        <div ng-include="'main.html" ng-controller="MainCtrl"></div>
        <div ui-view></div>
    <!--     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
     -->    <script src="../node_modules/angular/angular.js"></script>
    <!--     <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.js"></script>
     -->
        <script src="../node_modules/restangular/dist/restangular.js"></script>
        <script src="../node_modules/lodash/lodash.js"></script>

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

code main.html: 代码main.html:

<!—Displays error or success messages-->
            <span>{{message}}</span><br><br>

            <!—Login/logout form-->
            <form ng-show="!isAuthenticated" ng-submit="submit()">
                <label>Login Form:</label><br>
                <input ng-model="user.username" type="text" name="user" placeholder="Username" disabled="true" />
                <input ng-model="user.password" type="password" name="pass" placeholder="Password" disabled="true" />
                <input type="submit" value="Login" />
            </form>
            <div ng-show="isAuthenticated">
                <a ng-click="logout()" href="">Logout</a>
            </div>
            <div ui-view ng-show="isAuthenticated"></div>
            <br><br>

            <!—Displays contacts list-->
            <h1 ng-show="isAuthenticated">Liste des Contacts</h1>
            <article ng-repeat="contact in contacts" ng-show="isAuthenticated" id="{{ contact['@id'] }}" class="row marketing">
                <h2>{{ contact.nom }}</h2>
                <!—Displays contact phones list-->
                <h3 ng-repeat="moyenComm in contact.moyensComm">Tél : {{ moyenComm.numero }}</h3>
            </article><hr>

            <!—Create contact form-->
            <form name="createContactForm" ng-submit="createContact(createContactForm)" ng-show="isAuthenticated" class="row marketing">
                <h2>Création d'un nouveau contact</h2>
                <!—Displays error / success message on creating contact-->
                <div ng-show="contactSuccess" class="alert alert-success" role="alert">Contact publié.</div>
                <div ng-show="contactErrorTitle" class="alert alert-danger" role="alert">
                    <b>{{ contactErrorTitle }}</b><br>
                    {{ contactErrorDescription }}
                </div>
                <div class="form-group">
                    <input ng-model="newContact.nom" placeholder="Nom" class="form-control">
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
            </form>

            <!—Phone form-->
            <form name="createPhoneForm" ng-submit="createPhone(createPhoneForm)" ng-show="isAuthenticated" class="row marketing">
                <h2>Création d'un nouveau téléphone</h2>
                <div ng-show="phoneSuccess" class="alert alert-success" role="alert">Téléphone publié.</div>
                <div ng-show="phoneErrorTitle" class="alert alert-danger" role="alert">
                    <b>{{ phoneErrorTitle }}</b><br>
                    {{ phoneErrorDescription }}
                </div>
                <div class="form-group">
                    <input ng-model="newPhone.numero" placeholder="Numéro" class="form-control">
                </div>
                <div class="form-group">
                    <label for="contact">Contact</label>
                    <!—SelectBox de liste de contacts-->
                    <select ng-model="newPhone.contact" ng-options="contact['@id'] as contact.nom for contact in contacts" id="contact"></select>
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
            </form>

code app.js: 代码app.js:

'use strict';

    var app = angular
        .module('angularApp', ['restangular'])
    app.config(['RestangularProvider', function (RestangularProvider) {
            // URL ENDPOINT TO SET HERE !!!
            RestangularProvider.setBaseUrl('http://your_vhost/api');

            RestangularProvider.setRestangularFields({
                id: '@id'
            });
            RestangularProvider.setSelfLinkAbsoluteUrl(false);

            RestangularProvider.addResponseInterceptor(function (data, operation) {
                function populateHref(data) {
                    if (data['@id']) {
                        data.href = data['@id'].substring(1);
                    }
                }

                populateHref(data);

                if ('getList' === operation) {
                    var collectionResponse = data['hydra:member'];
                    collectionResponse.metadata = {};

                    angular.forEach(data, function (value, key) {
                        if ('hydra:member' !== key) {
                            collectionResponse.metadata[key] = value;
                        }
                    });

                    angular.forEach(collectionResponse, function (value) {
                        populateHref(value);
                    });

                    return collectionResponse;
                }

                return data;
            });
        }])
    ;

code main.js: 代码main.js:

'use strict';

    var app = angular
        .module('angularApp')
    app.controller('MainCtrl', function ($scope, $http, $window, Restangular) {
            // fosuser user
            $scope.user = {username: 'johndoe', password: 'test'};

            // var to display login success or related error
            $scope.message = '';

            // In my example, we got contacts and phones
            var contactApi = Restangular.all('contacts');
            var phoneApi = Restangular.all('telephones');

            // This function is launched when page is loaded or after login
            function loadContacts() {
                // get Contacts
                contactApi.getList().then(function (contacts) {
                    $scope.contacts = contacts;
                });

                // get Phones (throught abstrat CommunicationWays alias moyensComm)
                phoneApi.getList().then(function (phone) {
                    $scope.phone = phone;
                });

                // some vars set to default values
                $scope.newContact = {};
                $scope.newPhone = {};
                $scope.contactSuccess = false;
                $scope.phoneSuccess = false;
                $scope.contactErrorTitle = false;
                $scope.contactErrorDescription = false;
                $scope.phoneErrorTitle = false;
                $scope.phoneErrorDescription = false;

                // contactForm handling
                $scope.createContact = function (form) {
                    contactApi.post($scope.newContact).then(function () {
                        // load contacts & phones when a contact is added
                        loadContacts();

                        // show success message
                        $scope.contactSuccess = true;
                        $scope.contactErrorTitle = false;
                        $scope.contactErrorDescription = false;

                        // re-init contact form
                        $scope.newContact = {};
                        form.$setPristine();

                        // manage error handling
                    }, function (response) {
                        $scope.contactSuccess = false;
                        $scope.contactErrorTitle = response.data['hydra:title'];
                        $scope.contactErrorDescription = response.data['hydra:description'];
                    });
                };

                // Exactly same thing as above, but for phones
                $scope.createPhone = function (form) {
                    phoneApi.post($scope.newPhone).then(function () {
                        loadContacts();

                        $scope.phoneSuccess = true;
                        $scope.phoneErrorTitle = false;
                        $scope.phoneErrorDescription = false;

                        $scope.newPhone = {};
                        form.$setPristine();
                    }, function (response) {
                        $scope.phoneSuccess = false;
                        $scope.phoneErrorTitle = response.data['hydra:title'];
                        $scope.phoneErrorDescription = response.data['hydra:description'];
                    });
                };
            }

            // if a token exists in sessionStorage, we are authenticated !
            if ($window.sessionStorage.token) {
                $scope.isAuthenticated = true;
                loadContacts();
            }

            // login form management
            $scope.submit = function() {
                // login check url to get token
                $http({
                    method: 'POST',
                    url: 'http://your_vhost/login_check',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    data: $.param($scope.user)

                    // with success, we store token to sessionStorage
                }).success(function(data) {
                    $window.sessionStorage.token = data.token;
                    $scope.message = 'Successful Authentication!';
                    $scope.isAuthenticated = true;

                    // ... and we load data
                    loadContacts();

                    // with error(s), we update message
                }).error(function() {
                    $scope.message = 'Error: Invalid credentials';
                    delete $window.sessionStorage.token;
                    $scope.isAuthenticated = false;
                });
            };

            // logout management
            $scope.logout = function () {
                $scope.message = '';
                $scope.isAuthenticated = false;
                delete $window.sessionStorage.token;
            };

            // This factory intercepts every request and put token on headers
        })
        app.factory('authInterceptor', function($rootScope, $q, $window) {
        return {
            request: function (config) {
                config.headers = config.headers || {};

                if ($window.sessionStorage.token) {
                    config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
                }
                return config;
            },
            response: function (response) {
                if (response.status === 401) {
                    // if 401 unauthenticated
                }
                return response || $q.when(response);
            }
        };
    // call the factory ...
    })
    app.config(function ($httpProvider) {
        $httpProvider.interceptors.push('authInterceptor');
    });

help me please for resolve this bug and thanks advanced 请帮助我解决此错误,并感谢高级

I think isUndefined is a function in underscore.js, which is a dependency of Restangular: 我认为isUndefined是underscore.js中的一个函数,它是Restangular的依赖项:

http://underscorejs.org/#isUndefined http://underscorejs.org/#isUndefined

Do you have underscore.js included in your assets? 您的资产中是否包含underscore.js?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由于以下原因,无法实例化模块ngAnimate: - Failed to instantiate module ngAnimate due to: 未能实例化模块启动器 - Failed to instantiate module starter due AngularJS/TypeScript:由于服务无法实例化模块 - AngularJS/TypeScript: Failed to instantiate module due to service 由于在AngularJS中无法实例化模块应用? - Failed to instantiate module app due to in AngularJS? Angular JS:由于以下原因,无法实例化模块测试: - Angular JS : Failed to instantiate module test due to: 出现错误“由于以下原因,无法实例化模块{0}:\\ n {1}” - Getting error “Failed to instantiate module {0} due to:\n{1}” 错误:无法实例化模块restangular,原因是:'_'未定义 - Error: Failed to instantiate module restangular due to: '_' is undefined 由于以下原因而无法实例化模块[模块名称]:错误:[$ injector:modulerr] - Failed to instantiate module [module name] due to: Error: [$injector:modulerr] 由于以下原因,无法实例化模块应用程序:错误:模块“应用程序”不可用 - Failed to instantiate module Application due to: Error: Module 'Application' is not available $injector:modulerr 由于 $injecto 无法实例化模块 cloudinary<omitted> - $injector:modulerr Failed to instantiate module cloudinary due to $injecto <omitted>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM