简体   繁体   English

引用的错误:app.js第1行中未定义angular

[英]Referenced Error: angular is not defined in app.js line 1

index.js index.js

angular.module("travel")

.controller('LoginCtrl', function($scope, AuthService, $ionicPopup, $state) {
  $scope.user = {
    name: '',
    password: ''
  };

  $scope.login = function() {
    AuthService.login($scope.user).then(function(msg) {
      $state.go('inside');
    }, function(errMsg) {
      var alertPopup = $ionicPopup.alert({
        title: 'Login failed!',
        template: errMsg
      });
    });
  };
})

.controller('RegisterCtrl', function($scope, AuthService, $ionicPopup, $state) {
  $scope.user = {
    name: '',
    password: ''
  };

  $scope.signup = function() {
    AuthService.register($scope.user).then(function(msg) {
      $state.go('outside.login');
      var alertPopup = $ionicPopup.alert({
        title: 'Register success!',
        template: msg
      });
    }, function(errMsg) {
      var alertPopup = $ionicPopup.alert({
        title: 'Register failed!',
        template: errMsg
      });
    });
  };
})

.controller('InsideCtrl', function($scope, AuthService, API_ENDPOINT, $http, $state) {
  $scope.destroySession = function() {
    AuthService.logout();
  };

  $scope.getInfo = function() {
    $http.get(API_ENDPOINT.url + '/memberinfo').then(function(result) {
      $scope.memberinfo = result.data.msg;
    });
  };

  $scope.logout = function() {
    AuthService.logout();
    $state.go('outside.login');
  };
})

.controller('AppCtrl', function($scope, $state, $ionicPopup, AuthService, AUTH_EVENTS) {
  $scope.$on(AUTH_EVENTS.notAuthenticated, function(event) {
    AuthService.logout();
    $state.go('outside.login');
    var alertPopup = $ionicPopup.alert({
      title: 'Session Lost!',
      template: 'Sorry, You have to login again.'
    });
  });
});

app.js app.js

angular.module("travel" ,['ionic'])

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
  .state('outside', {
    url: '/outside',
    abstract: true,
    templateUrl: 'templates/outside.html'
  })

index.html index.html

  <!DOCTYPE html>
    <html>
        <head>

            <script type="text/javascript" src="angular.js"></script>
            <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script>
            <script src="js/app.js"></script>
            <script src="js/controllers.js"></script>
            <script src="js/services.js"></script>
            <script src="js/constants.js"></script>       
            <link rel="stylesheet" type="text/css" href="css/index.css">
            <title>FinalYearProject</title>
        </head>
        <body ng-app="travel" ng-controller="AppCtrl">
            <ui-view></ui-view>
        </body>
    </html>

i'm getting angular js not defined error by adding cdn of angular now i'm getting the error like 'travel' module is not found Anugular js code is also updated as index js Please help me in this error 我现在通过添加angular的cdn来获取angular js未定义的错误,但现在却遇到未找到“ travel”模块的错误,而Anugular js代码也已更新为索引js,请帮助我

HTML: HTML:

    <!DOCTYPE html>
    <html>
    <head>
        <script src="../bower_components/angular/angular.min.js"></script>
        <script src="../bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
// Some ionic reference
        <script src="app.js"></script>
        <script src="index.js"></script>
        <title>FinalYearProject</title>
    </head>
    <body ng-app="travel" ng-controller="AppCtrl">
        <div ui-view>
            {{1+1}}
        </div>
    </body>
    </html>

app.js app.js

(function () {
    'use strict';
    var app = angular.module('travel', ['ui.router','ionic']);
    //Configuration for Angular UI routing.
    app.config([
        '$stateProvider', '$urlRouterProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider) {
            $stateProvider
                .state('outside', {
                    url: '/outside',
                    template: '<h1>My Contacts</h1>'
                });
            $urlRouterProvider.otherwise('/outside');
        }
    ]);
})();

The angular js not defined error might be caused because maybe the cdn couldn't be reached. 角度js未定义错误可能是由于无法到达CDN引起的。 So the angular variable is not created and this, when in your app.js the line angular.module("travel" ,['ionic']) is reached, angular is not found. 因此,不会创建angular变量,并且在您的app.js中到达angular.module("travel" ,['ionic']) ,找不到angular

On the other hand your "travel" module is properly defined. 另一方面,您的“旅行”模块已正确定义。

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

相关问题 未捕获的ReferenceError:未定义角度app.js - Uncaught ReferenceError: angular is not defined app.js [eslint] src\App.js 第 2:8 行中的 React js 错误警告:'person' 已定义但从未使用过 - React js error WARNING in [eslint] src\App.js Line 2:8: 'person' is defined but never used ./src/App.js Line 6:19: &#39;Component&#39; 未定义 no-undef - ./src/App.js Line 6:19: 'Component' is not defined no-undef AngularJS:未捕获ReferenceError:未定义angular app.js:1(匿名函数): - AngularJS: Uncaught ReferenceError: angular is not defined app.js:1(anonymous function): React js:./src/App.js第22行:未定义&#39;lastWinner&#39;no-undef搜索关键字以了解有关每个错误的更多信息 - React js: ./src/App.js Line 22: 'lastWinner' is not defined no-undef Search for the keywords to learn more about each error 在./src/App.js&#39;store&#39;中的反应错误未定义 - react Error in ./src/App.js 'store' is not defined 我定义了组件并使用它 App.js 但出现未定义的错误 - I defined component and used it App.js but getting undefined error 调试未知错误。 Angular app.js - Debugging the unknown error. Angular app.js 定义的组件在 App.js 中不可访问 - Defined Component is not accessible in App.js 未捕获的ReferenceError:app.js中未定义require:3 - Uncaught ReferenceError: require is not defined at app.js:3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM