2014-06-22 113 views
2

我收到Angularjs未知的提供程序錯誤

Error: [$injector:unpr] Unknown provider: mvProfileCtrlProvider <- mvProfileCtrl 
在我的錯誤

,我已經確信,它包含在我的腳本,並訪問(我可以從chrome-debugger > sources > mvProfileCtrl.js打開它),所以它是可用於參考我猜。但還是這裏有兩個相關的文件:

angular.module('app').controller('navBarLoginController',function($scope,$http,mvIdentity,mvNotifier,mvAuth,mvProfileCtrl,$location) { 
    $scope.identity = mvIdentity; 
    $scope.signin = function(username,password) { 
     mvAuth.authenticateUser(username,password).then(function(success){ 
      if(success){ 
       mvNotifier.notify('You have successfully signed in!'); 
      }else{ 
       mvNotifier.notify('Username/Password combination incorrect'); 
      } 
     }) 
    } 
    var profile = mvProfileCtrl; 
    $scope.update = function(){ 
     profile.listen(mvIdentity.currentUser); 
    } 
    $scope.signout = function() { 
     mvAuth.logoutUser().then(function() { 
      $scope.username = ""; 
      $scope.password = ""; 
      mvNotifier.notify('You have successfully signed out!'); 
      $location.path('/'); 
     }) 
    } 
}) 

和 -

angular.module('app').controller('mvProfileCtrl', function($scope, mvAuth, mvIdentity, mvNotifier) { 
    $scope.mvIdentity = mvIdentity; 
    $scope.update = function() { 
     console.log("" + $scope.updateemail + " -- " + test); 
     var newUserData = { 
      username: $scope.updateemail, 
      firstName: $scope.updatefname, 
      lastName: $scope.updatelname 
     } 
     if($scope.updatepassword && $scope.updatepassword.length > 0) { 
      newUserData.password = $scope.updatepassword; 
     } 

     mvAuth.updateCurrentUser(newUserData).then(function() { 
      $('#profileModal').modal('toggle'); 
      mvNotifier.notify('Your user account has been updated'); 
     }, function(reason) { 
      mvNotifier.error(reason); 
     }) 
    } 
    return { 
     listen : function(currentUser) { 
      if (!currentUser) return; 
      $scope.updateemail = currentUser.username; 
      $scope.updatefname = currentUser.firstName; 
      $scope.updatelname = currentUser.lastName; 
      console.log("--> " + $scope.updateemail + " -- " + test); 
     } 
    } 
}); 

和腳本文件 - 在這裏

script(type="text/javascript", src="/vendor/jquery/dist/jquery.js") 
script(type="text/javascript", src="/vendor/toastr/toastr.js") 
script(type="text/javascript", src="/vendor/angular/angular.js") 
script(type="text/javascript", src="/vendor/angular-resource/angular-resource.js") 
script(type="text/javascript", src="/vendor/angular-route/angular-route.js") 
script(type="text/javascript", src="/vendor/bootstrap/dist/js/bootstrap.js") 
script(type="text/javascript", src="/vendor/bootstrap/js/dropdown.js") 
script(type="text/javascript", src="/app/app.js") 
script(type="text/javascript", src="/plugins/backstretch/jquery.backstretch.min.js") 
script(type="text/javascript", src="/plugins/bxslider/jquery.bxslider.min.js") 
script(type="text/javascript", src="/plugins/bxslider/jquery.bxslider.min.js") 
script(type="text/javascript", src="/app/account/navBarLoginController.js") 
script(type="text/javascript", src="/app/common/mvNotifier.js") 
script(type="text/javascript", src="/app/account/mvIdentity.js") 
script(type="text/javascript", src="/app/account/mvauth.js") 
script(type="text/javascript", src="/app/account/mvUser.js") 
script(type="text/javascript", src="/app/admin/mvUserListCtrl.js") 
script(type="text/javascript", src="/app/account/mvSignupCtrl.js") 
script(type="text/javascript", src="/app/account/mvProfileCtrl.js") 

回答

2

的問題是,您試圖注入控制器進入另一控制器。這是而不是它應該如何。

請檢查:

要看到,我們應該怎麼控制器之間通信 - 使用共享服務。

服務和控制器之間最大的區別是(見Developer Guide /Dependency Injection):

控制器的特別之處在於,不像服務,可以有他們的許多實例中的應用。例如,模板中的每個ng-controller指令都會有一個實例。

所以,當我們試圖調用另一個內部的一個控制器的方法......我們應該把它移動到一個單獨服務

相關問題