无法访问service.js中定义的离子,工厂和服务

时间:2016-09-08 18:27:55

标签: angularjs ionic-framework angular-services angular-controller

controller.js:

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


.controller('mobileCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams) {
    $scope.user = {} ;

    $scope.sendSMS = function(){
    console.log("Test L1");
    console.log($scope.user.mobile);
    var vCode = Math.floor(Math.random()*90000) + 10000;
    var mobile = $scope.user.mobile;
    var a = Calculator.square($scope.user.mobile);
    Console.log("Calculate return "+ a);

    SendSMSFactory.connectSMSGateway($mobile,$vCode).success(function(){   

        console.log("Success");
      //assign value
}).error(function(){
})
};


}])

.controller('signupCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams) {


}])

.controller('eventCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams) {


}])

.controller('verificationCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams) {


}])

.controller('interestCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams) {


}])

============

services.js

=======

angular.module('app.services', [])

.factory('BlankFactory', [function(){

}])

.factory('SendSMSFactory', [function($http){
        return {
     connectSMSGateway: function($mobileNumber,$vCode){
         console.log($mobileNumber);
         console.log($vCode);
        return $http.get('http://google.com');
     }
  };

}])

.service('Calculator', function () {
    this.square = function (a) { return a*a};

})

.service('BlankService', [function(){
        console.log("Blank Service");

}]);

每当我尝试在控制器上运行时,它都无法找到services.js中定义的任何方法,无论是工厂还是服务。它是投掷计算器未定义的错误。

我知道我缺少非常基本的东西,但无法弄明白。

请帮忙。

============== app.js

    // Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.directives','app.services'])

.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 && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

1 个答案:

答案 0 :(得分:0)

问题是,我没有在控制器中传递服务名称或工厂名称。 而不是函数($ scope,$ stateParams), 它应该是函数($ scope,$ stateParams,Calculator,SendSMSFactory)