私はこのチュートリアルhttps://thinkster.io/tutorials/mean-stack/wiring-everything-upで角度を覚えようとしています。アプリケーションを開くと、/ posts URLを呼び出す無限ループが発生します。私は郵便配達員と私のルートをチェックして、彼らは意図したように働いているので、なぜこれが正しく解決されないのか分かりません。以下は、 'posts'サービス、 'mainCtrl'コントローラー、および設定です。誰かが見て、私のエラーが表示された場合、または私が助けるためにコードの多くを提供する必要があるかどうか教えてください。ありがとうございました。無限ループを引き起こす角度uiルータ
サービス
app.factory('posts', ['$http', function($http){
var o = {
posts:[]
}
o.getAll = function() {
return $http.get('/posts').success(function(data){
angular.copy(data, o.posts);
});
};
return o;
}])
コントローラ
app.controller('MainCtrl', ['$scope', 'posts', function($scope, posts){
$scope.test = 'Hello world!';
$scope.posts = posts.posts;
$scope.addPost = function(){
if(!$scope.title || $scope.title === '') { return; }
$scope.posts.push({
title: $scope.title,
link: $scope.link,
upvotes: 0,
comments: [
{author: 'Joe', body: 'Cool post!', upvotes: 0},
{author: 'Bob', body: 'Great idea but everything is wrong!', upvotes: 0}
]
});
$scope.title='';
$scope.link='';
}
$scope.incrementUpvotes = function(post) {
post.upvotes += 1;
};
}]);
コンフィグ
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
$stateProvider
.state('home', {
url:'/home',
templateUrl:'/home.html',
controller:'MainCtrl',
resolve: {
postPromise: ['posts', function(posts){
return posts.getAll();
}]
}
})
.state('posts', {
url:'/posts/{id}',
templateUrl:'/posts.html',
controller:'PostsCtrl'
})
$urlRouterProvider.otherwise('home');
}])
入力いただきありがとうございます。私はこれをチェックしましたが、無限ループの問題を解決できませんでした。 –
'return angular.copy(data、o.posts);' – rrd
申し訳ありませんが、それも修正されませんでした。これはリポジトリです。詳しくは https://github.com/RawleJuglal/rawle_news_appをご覧ください。 –