离子模块“studController”不可用

时间:2022-08-14 20:28:59

I'm trying to display json data into html using ionic framework. I receive this error.

我正在尝试使用离子框架将json数据显示到html中。我收到此错误。

info.html

<ion-view ng-controller="studController" >
  <ion-content padding = "true">
   <div class="list list-inset">
    <button ng-click = "studController.loadDetails()">Click</button>
    <div class="item" ng-repeat="val in servicedata">
        {{val}}
    </div>
   </div>
  </ion-content>
</ion-view>

app.js

var app = angular.module('starter', ['ionic', 'studController'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
 if(window.cordova && window.cordova.plugins.Keyboard) {
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
 }
   if(window.StatusBar) {
      StatusBar.styleDefault();
   }
 });
});
function AppConfigScreens($stateProvider, $urlRouterProvider){
//url settings
$stateProvider
.state('display_information', {url: '/display_information',templateUrl:     'templates/display_information.html',controller:'studController'});
$urlRouterProvider
.otherwise('/display_information');
 }
app.config(['$stateProvider', '$urlRouterProvider',AppConfigScreens]);

controller.js

var controllerID = 'studController';
angular.module('starter').controller(controllerID, ['$window', '$rootScope', '$scope', '$state', '$log','services', studController]);

function studController($window, $rootScope, $scope, $state, $log, services){
self.loadDetails = loadDetails;
$ionicPlatform.ready(function(){
    function loadDetails(){
        var promiseGet = services.getValue();
        promiseGet.then(function(responsevalue){
            this.servicedata = responsevalue;
            alert(servicedata);
        });
    }
}); 
}

service.js

angular.module('starter').factory('services',['$rootScope', '$http', '$q', '$timeout', '$log',services]);

 function services($rootscope, $http, $q, $timeout, $ionicPlatform){
    var service = { 
        getValue : getValue,
    };
 return service;
 function getValue(){
        var d = $q.defer();
        var url = "http://192.168.1.16:8000/student_view/"
        alert(url);
        $http.get(url).success(function(data) {
            $log.log("REST API Response:" + data);
            alert(data)
            d.resolve(data);
        }).error(function(error) {
            d.reject(error);
        });
        return d.promise;
    } 
}

I get this error

我收到这个错误

Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to: Error: [$injector:modulerr] Failed to instantiate module studController due to: Error: [$injector:nomod] Module 'studController' is not available! You either misspell......2) ionic.bundle.js:8762

未捕获错误:[$ injector:modulerr]由于以下原因无法实例化模块启动器:错误:[$ injector:modulerr]由于以下原因无法实例化模块studController:错误:[$ injector:nomod]模块'studController'不可用!你要么拼错...... 2)ionic.bundle.js:8762

1 个解决方案

#1


In your code studController is a controller. The error is because angular is not able to locate a module called studController. We only include modules like that and not controllers. Hence change this line:

在你的代码中,studController是一个控制器。错误是因为angular无法找到名为studController的模块。我们只包含那样的模块而不是控制器。因此改变这一行:

var app = angular.module('starter', ['ionic', 'studController'])

to

var app = angular.module('starter', ['ionic'])

and hopefully it should work.

并希望它应该工作。

#1


In your code studController is a controller. The error is because angular is not able to locate a module called studController. We only include modules like that and not controllers. Hence change this line:

在你的代码中,studController是一个控制器。错误是因为angular无法找到名为studController的模块。我们只包含那样的模块而不是控制器。因此改变这一行:

var app = angular.module('starter', ['ionic', 'studController'])

to

var app = angular.module('starter', ['ionic'])

and hopefully it should work.

并希望它应该工作。