2016-10-25 11 views
0

角度ngResourceに問題があります。私は、依存関係を追加するとページが読み込まれていません...ここに私のコードは次のとおりです。私は、コードの最初の部分のコメントを外したときにngResourceとSPA angularjsが表示されない

/*var app = angular.module('myApp', ['ngResource']); 

app.factory('todoFactory', function($resource) { 
    return $resource('/api/meetups'); 
});*/ 

angular.module('myApp').controller('loginController', 
    ['$scope', '$location', 'AuthService', 
    function ($scope, $location, AuthService) { 

    $scope.login = function() { 

     // initial values 
     $scope.error = false; 
     $scope.disabled = true; 

     // call login from service 
     AuthService.login($scope.loginForm.username, $scope.loginForm.password) 
     // handle success 
     .then(function() { 
      $location.path('/'); 
      $scope.disabled = false; 
      $scope.loginForm = {}; 
     }) 
     // handle error 
     .catch(function() { 
      $scope.error = true; 
      $scope.errorMessage = "Invalid username and/or password"; 
      $scope.disabled = false; 
      $scope.loginForm = {}; 
     });  
    };  
}]); 

angular.module('myApp').controller('logoutController', 
    ['$scope', '$location', 'AuthService', '$resource', 
    function ($scope, $location, AuthService) { 

    $scope.logout = function() { 

     // call logout from service 
     AuthService.logout() 
     .then(function() { 
      $location.path('/login'); 
     });  
    }; 

/* 

$scope.posts = []; 
    $scope.newPost = {created_by: '', text: '', create_at: ''}; 

    $scope.afficher = function(){ 
     $scope.newPost.created_at = Date.now(); 
     $scope.posts.push($scope.newPost); 
     $scope.newPost = {created_by: '', text: '', created_at: ''}; 
    };  
*/ 
    $scope.meetups = []; 
    /*var Meetup = $resource('/api/meetups'); 

    Meetup.query(function (results) { 
    $scope.meetups = results; 
    }); 

    $scope.meetups = [] 

    $scope.createMeetup = function() { 
    var meetup = new Meetup(); 
    meetup.name = $scope.meetupName; 
    meetup.$save(function (result) { 
     $scope.meetups.push(result); 
     $scope.meetupName = ''; 
    }); 
    }*/ 
}]); 

angular.module('myApp').controller('registerController', 
    ['$scope', '$location', 'AuthService', 
    function ($scope, $location, AuthService) { 

    $scope.register = function() { 

     // initial values 
     $scope.error = false; 
     $scope.disabled = true; 

     // call register from service 
     AuthService.register($scope.registerForm.username, $scope.registerForm.password) 
     // handle success 
     .then(function() { 
      $location.path('/login'); 
      $scope.disabled = false; 
      $scope.registerForm = {}; 
     }) 
     // handle error 
     .catch(function() { 
      $scope.error = true; 
      $scope.errorMessage = "Something went wrong!"; 
      $scope.disabled = false; 
      $scope.registerForm = {}; 
     });  
    };  
}]); 

問題が発生します。私は本当に立ち往生している提案や情報を受け入れるので、私を助けてください。私は必要に応じてコードを追加します。

答えて

0

これは、そのように、まず、第1のコード部分をアンコメントあなたはそれを作成したら、あなたは

angular.('appName').controller(.... or ngular.('appName').directive 

により、コントローラ、またはディレクティブを作成するために使用することができ、あなたのモジュールを作成する方法

angular.module('appName',[/*dependancies*/] 

で、エラーの解決策を見つけてください。あなたのhtmlファイルにngResourceのスクリプトリファレンスを追加していない可能性があります。 スクリプト参照の直後にangleを追加してください。

+0

私はスクリプトリファレンスを追加しました。私はそれが何も表示されていない最初の部分のコメントを外し、私はコンソール上のエラーを取得しないでください...助けてください –

0

工場出荷時のログアウトコントローラ&には、$リソースがありません。

また、あなたのプロジェクト/ htmlに角度リソースjsがあることを確認してください。

var app = angular.module('myApp', ['ngResource']); 

app.factory('todoFactory', ['$resource' , function($resource) { 
    return $resource('/api/meetups'); 
}]); 




    angular.module('myApp').controller('logoutController', 
     ['$scope', '$location', 'AuthService', '$resource', 
     function ($scope, $location, AuthService,$resource) //here. 
{ 

     $scope.logout = function() { 

      // call logout from service 
      AuthService.logout() 
      .then(function() { 
       $location.path('/login'); 
      });  
     }; 
    } 
関連する問題