错误:未捕获ReferenceError:在controllers.js:1中未定义角度

时间:2019-05-22 09:38:44

标签: angularjs angular ionic-framework

我正在尝试在离子项目中使用离子操作表,但是在控制台中却显示错误:- 未捕获ReferenceError:未定义角度     在controllers.js:1

能否请您帮我解决此错误。 请参阅下面的controllers.js文件代码

     angular.module('starter.controllers', [])

     .controller('AppCtrl', function($scope, $ionicModal, $timeout) {


      })


      .controller('myCtrl', function($scope, $ionicActionSheet) {
       $scope.triggerActionSheet = function() {
       // Show the action sheet
       var showActionSheet = $ionicActionSheet.show({
        buttons: [
         { text: 'Edit 1' },
         { text: 'Edit 2' }
        ],

       destructiveText: 'Delete',
       titleText: 'Action Sheet',
       cancelText: 'Cancel',

       cancel: function() {
        // add cancel code...
       },

       buttonClicked: function(index) {
        if(index === 0) {
           // add edit 1 code
        }

        if(index === 1) {
           // add edit 2 code
        }
       },

        destructiveButtonClicked: function() {
        // add delete code..
       }
      });
     };
    })

以下是index.html文件的代码

 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
 <title></title>
 <link rel="manifest" href="manifest.json">
 <link href="lib/ionic/css/ionic.css" rel="stylesheet">
 <link href="css/style.css" rel="stylesheet">
 <script src="js/controllers.js"></script>
 <!-- ionic/angularjs js -->
 <script src="lib/ionic/js/ionic.bundle.js"></script>
 <!-- cordova script (this will be a 404 during development) -->
 <script src="cordova.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> 
 </script>

<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
    <ion-content>

    <button class = "button">Action Sheet Button</button>
  </ion-content>
  </ion-pane>
   </body>
  </html>

1 个答案:

答案 0 :(得分:1)

您在包含angular libary之前包含了controllers.js。首先添加角度

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"/> 

在包含controllers.js之前

<script src="js/controllers.js"></script>