三个相关的问题:参数' MainCtrl'不是一个功能和模块' myApp'不可用

时间:2016-12-13 11:20:02

标签: angularjs ionic-framework

我遇到了这三个问题,我认为这些问题有关。我读了很多Stackoverflow帖子,谷歌就读了2天,但因为我和离子创作者一起工作,我没有找到合适的答案...

奇怪的事实是我可以运行并使用我的应用程序,除了一个MainCtrl函数,它可以工作,但我仍然有这些错误消息:

错误:[$ injector:nomod]模块' myApp'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

错误:[ng:areq]参数' MainCtrl'不是一个功能,未定义 http://errors.angularjs.org/1.5.3/ng/areq?p0=MainCtrl&p1=not%20aNaNunction%2C%20got%20undefined

错误:[ng:areq]参数' LoadingCtrl'不是一个功能,未定义

这是我的代码,我确定这是一个小错误,但我无法弄清楚:



// Here is the module declaration

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

// The first controller's

myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function($scope, $ionicPopup, $timeout) {
  
$scope.createPopUpService = function(){

var newTemplate = '<div>Hi</div>';  
  
var myService = $ionicPopup.show({
        template: newTemplate,
        title: 'Test',
        scope: $scope,
        cssClass: 'popJoinService',
        buttons: [
              { text: '<b>Cancel<b/>',
                type: 'button-assertive'
              },
              {
                text: '<b>OK</b>',
                type: 'button-positive',
                onTap: function(e) {
                    console.log("Hello");
                  }
              }
            ]
          });
};
}]);

// The second controller's

myApp.controller('LoadingCtrl', function($scope, $ionicLoading) {
  $scope.show = function() {
    $ionicLoading.show({
      template: 'Loading...',
      duration: 3000
    }).then(function(){
       console.log("The loading indicator is now displayed");
    });
  };
  $scope.hide = function(){
    $ionicLoading.hide().then(function(){
       console.log("The loading indicator is now hidden");
    });
  };
});
&#13;
<ion-view title="HTML1" style="background-color:#93E693;">
  <div ng-app="app.directives">
    <ion-refresher (ionRefresh)="doRefresh($event)" ng-controller ="LoadingCtrl">
                <ion-refresher-content
                      pullingIcon="arrow-dropdown"
                      pullingText="Pull to refresh"
                      refreshingSpinner="circles"
                      refreshingText="Refreshing...">
                </ion-refresher-content>
    </ion-refresher>
  </div>
  
<!-- I also tried this : ng-app="myApp" and ng-app="" but it seems the change as no effect on the result-->
<!-- Because it is ionic creator, I can't add scripts like usually -->
  
  <div ng-app="app.directives" ng-controller="MainCtrl">
      <button class="item-avatar button  button-small button-calm  button-block icon-left ion-android-add" ng-click="createPopUpService()">test button</button>
  </div>
  
</ion-view>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

尝试没有标点符号。

var myApp = angular.module('yourAppName', []);

尝试使用正文或HTML代码。

<body ng-app="yourAppName">

<html ng-app="yourAppName">

myApp是可变的,适用于Javascript。

var myApp = angular.module('yourAppName', []);
myApp.controller('MainController', function ( $scope, $rootScope ){
 //Controller code
});