0

我在控制台中收到错误。我使用离子-V1具有角和我的后端是PHP,MySQL的

Error: [$injector:unpr] Unknown provider: starterServiceProvider <- starterService 
    http://errors.angularjs.org/1.2.12/$injector/unpr?p0=starterServiceProvider%20%3C-%20starterService 
     at ionic.bundle.js:7536 
     at ionic.bundle.js:11004 
     at Object.getService [as get] (ionic.bundle.js:11131) 
     at ionic.bundle.js:11009 
     at getService (ionic.bundle.js:11131) 
     at invoke (ionic.bundle.js:11158) 
     at Object.instantiate (ionic.bundle.js:11179) 
     at ionic.bundle.js:14238 
     at ionic.bundle.js:13647 
     at forEach (ionic.bundle.js:7768) 

这是我的app.js

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

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 

这是我的controllers.js
它是注入一个控制器数据从HTML页面和正在添加呼叫服务"starterServices"

.controller('ToDoListCtrl',['starterService' , function($scope,$ionicModal,starterService) { 
     $scope.toDoListItems = [{ 
     task: 'Scuba Diving', 
     status: 'not done' 
     }, { 
     task: 'Climb Everest', 
     status: 'not done' 
     }]; 

    $scope.AddItem = function(data){ 
     var addTask = starterService.addtask(); 
     addTask.then(function(data){ 
      $scope.task = data.task; 
      $scope.status = data.status; 
     }); 
     }; 
     /*$scope.toDoListItems.push({task:data.newItem,status:'not done'}); 
     data.newItem = ' '; 
      $scope.closeModalAdd();*/ 

    $scope.DeleteItem = function(data){ 
      var ans = confirm('Are you sure to delete it?'); 
      if(ans){ 
      var deleteTask = starterService.delTask(task); 

      alert('Sucessfully deleted task ',+ data.task); 

      } 

     /* 
     $scope.toDoListItems.pop({task: data.newItem}); 
     data.newItem = ' '; 
      $scope.closeModalDelete(); 
     */ 
     alert('Sucessfully deleted task '); 

     }; 

    $ionicModal.fromTemplateUrl('modal.html', { 
     scope: $scope, 
     animation: 'slide-in-up' 
     }).then(function(modal) { 
     $scope.modal = modal; 
     }); 

    $ionicModal.fromTemplateUrl('dmodal.html', { 
     scope: $scope, 
     animation: 'slide-in-up' 
     }).then(function(dmodal) { 
     $scope.dmodal = dmodal; 
     }); 

     $scope.openModalAdd = function() { 
     $scope.modal.show(); 
     }; 
     $scope.closeModalAdd = function() { 
     $scope.modal.hide(); 
     }; 

     $scope.openModalDelete = function() { 
     $scope.dmodal.show(); 
     }; 
     $scope.closeModalDelete = function() { 
     $scope.dmodal.hide(); 
     }; 
     //Cleanup the modal when we're done with it! 
     $scope.$on('$destroy', function() { 
     $scope.modal.remove(); 
      $scope.dmodal.remove(); 
     }); 

    }]); 

,这是我service.js

app.service('starterService', function($http){ 

    var serviceUrl = "http://localhost/2404/CRUD Ionic/www/php/"; 

    this.addtask = function(data){ 
     var response = $http({ 
      method : "POST", 
      url : serviceUrl + "createTask.php", 
      params : data 
     }); 
     return response; 

    }; 
    this.delTask = function(task){ 
     var response = $http ({ 
      method : "POST", 
      usr : serviceUrl + "deleteTask.php", 
      params : {task} 
     }); 
     return response; 
    }; 


});  
+0

您是否在'html'页面中加入了'service.js'? –

+0

是在头 <! - 您的应用程序的JS - >

回答

1

的应用模块应该是这样的:

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

,因为它有一个名为'starterService'任何模块没有依赖关系。这是一种服务,而不是一个模块。这里只允许将模块添加为依赖项。

更新:

你忘了提供适当的依赖映射为好。

.controller('ToDoListCtrl',['$scope','$ionicModal', 'starterService' , function($scope,$ionicModal,starterService) { 
    $scope.toDoListItems = [{ 
    task: 'Scuba Diving', 
    status: 'not done' 
    }, { 
    task: 'Climb Everest', 
    status: 'not done' 
    }]; 

$scope.AddItem = function(data){ 
    var addTask = starterService.addtask(); 
    addTask.then(function(data){ 
     $scope.task = data.task; 
     $scope.status = data.status; 
    }); 
    }; 
    /*$scope.toDoListItems.push({task:data.newItem,status:'not done'}); 
    data.newItem = ' '; 
     $scope.closeModalAdd();*/ 

$scope.DeleteItem = function(data){ 
     var ans = confirm('Are you sure to delete it?'); 
     if(ans){ 
     var deleteTask = starterService.delTask(task); 

     alert('Sucessfully deleted task ',+ data.task); 

     } 

    /* 
    $scope.toDoListItems.pop({task: data.newItem}); 
    data.newItem = ' '; 
     $scope.closeModalDelete(); 
    */ 
    alert('Sucessfully deleted task '); 

    }; 

$ionicModal.fromTemplateUrl('modal.html', { 
    scope: $scope, 
    animation: 'slide-in-up' 
    }).then(function(modal) { 
    $scope.modal = modal; 
    }); 

$ionicModal.fromTemplateUrl('dmodal.html', { 
    scope: $scope, 
    animation: 'slide-in-up' 
    }).then(function(dmodal) { 
    $scope.dmodal = dmodal; 
    }); 

    $scope.openModalAdd = function() { 
    $scope.modal.show(); 
    }; 
    $scope.closeModalAdd = function() { 
    $scope.modal.hide(); 
    }; 

    $scope.openModalDelete = function() { 
    $scope.dmodal.show(); 
    }; 
    $scope.closeModalDelete = function() { 
    $scope.dmodal.hide(); 
    }; 
    //Cleanup the modal when we're done with it! 
    $scope.$on('$destroy', function() { 
    $scope.modal.remove(); 
     $scope.dmodal.remove(); 
    }); 
+0

得到这个错误:[$ injector:unpr]未知的提供者:starterServiceProvider < - starterService –

+0

@NasiruddinSaiyed我已经更新了答案。我没有注意到您将自我模块添加为依赖项。立即尝试。 –

+0

@NasiruddinSaiyed请参阅控制器更新。您忘记提供适当的依赖关系映射。 –

相关问题