离子模块“studController”不可用

时间:2015-05-05 04:51:12

标签: javascript angularjs ionic-framework

我正在尝试使用离子框架将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;
    } 
}

我收到此错误

  

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

1 个答案:

答案 0 :(得分:0)

在您的代码中studControllercontroller。该错误是因为angular无法找到名为module的{​​{1}}。我们只包含那样的模块而不是控制器。因此改变这一行:

studController

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

希望它能够奏效。