javascript - ionic 模块 "studController"不可用

标签 javascript angularjs ionic-framework

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

信息.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;
    } 
}

我收到此错误

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

最佳答案

在您的代码中,studController 是一个 Controller 。该错误是因为 Angular 无法找到名为 StudController 的模块。我们只包含这样的模块,而不包含 Controller 。因此更改这一行:

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

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

希望它能起作用。

关于javascript - ionic 模块 "studController"不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30044521/

相关文章:

javascript - 使用 javascript 将 Django timesince 的输出解析为浮点天数

javascript - AngularJS angular-ui bootstrap timepicker 作为下拉菜单

javascript - AngularJS OnsenUI 在子页面的 nav.popPage() 上重新加载父页面

css - ionic 2 : Display array of items in a 3x3 table

javascript - 在绝对定位的父级内滚动 Div

javascript - 如何使用 JSX 'collected' 将 React 元素上的属性定义为单个对象?

javascript - 在meteor-jasmine中测试router.go的点击事件

javascript - 文件上传 |没有页面刷新 |支柱2 |没有闪光 |

javascript - AngularJS:在指令的链接函数中监视异步值

angularjs - Cordova SQLite 等到插入完成