错误:$ resource:badcfg响应与配置的参数 - AngularJs不匹配

时间:2017-07-02 17:08:50

标签: javascript angularjs json ionic-framework

在我的离子应用中,我有一项服务,如图所示。

  .factory('newsFactory',['$resource', 'baseURL', function($resource,baseURL) {

      return $resource(baseURL + "news/:id", null, {
                'update': {
                      method: 'PUT'
                 }
      });   


}])

然后我在DishDetailController中注入上面的工厂。我希望用户连续点击并获取我的新闻json数组的特定文章。即http://localhost:3000/news/1,http://localhost:3000/news/2等等。

  .controller('NewsController', ['$scope', 'newsFactory', function($scope, newsFactory) {

                    $scope.message = "Loading ...";

                    $scope.newsZero = newsFactory.query(
                                function(response) {
                                    var news = response;
                                        $scope.newsZero = news[0];
                                        console.log($scope.newsZero);

                                },
                                function(response) {
                                    $scope.message = "Error: "+response.status + " " + response.statusText;
                                });

                                $scope.newsOne = newsFactory.query(
                                function(response) {
                                    var news = response;
                                    $scope.newsOne = news[1];
                                    console.log($scope.newsOne);
                                },
                                function(response) {
                                    $scope.message = "Error: "+response.status + " " + response.statusText;
                                });

                                $scope.newsTwo = newsFactory.query(
                                function(response) {
                                    var news = response;
                                    $scope.newsTwo = news[2];
                                    console.log($scope.newsTwo);
                                },
                                function(response) {
                                    $scope.message = "Error: "+response.status + " " + response.statusText;
                                });

                                $scope.newsThree = newsFactory.query(
                                function(response) {
                                    var news = response;
                                    $scope.newsThree = news[3];
                                    console.log($scope.newsThree);
                                },
                                function(response) {
                                    $scope.message = "Error: "+response.status + " " + response.statusText;
                                });

        }])
.controller('NewsDetailsController', ['$scope', '$stateParams', 'newsFactory', function($scope, $stateParams, newsFactory) {

                 $scope.detailedNews = newsFactory.get({
                    id: $stateParams.id
                 })
                 .$promise.then(
                    function (response) {
                        $scope.detailedNews = response;

                    },
                    function (response) {
                        $scope.message = "Error: " + response.status + " " + response.statusText;
                    }
                );


 }]);

我可以使用此代码在卡片视图中显示所有json对象。

                    <ion-view view-title="News">
                  <ion-content>

                    <div class="card">

                          <div class="item item-thumbnail-left item-text-wrap" ui-sref="app.newsdetails({id: newsZero._id})">
                               <img ng-src="{{newsZero.image}}" alt="{{newsZero.image}}">
                              <h2>{{newsZero.title}}</h2>

                          </div>
                      </div>
                      <div class="card">

                          <div class="item item-thumbnail-left item-text-wrap" ui-sref="app.newsdetails({id: newsOne._id})">
                               <img ng-src="{{newsOne.image}}" alt="{{newsOne.image}}">
                              <h2>{{newsOne.title}}</h2>

                          </div>
                      </div>
                      <div class="card">

                          <div class="item item-thumbnail-left item-text-wrap" ui-sref="app.newsdetails({id: newsTwo._id})">
                               <img ng-src="{{newsTwo.image}}" alt="{{newsTwo.image}}">
                              <h2>{{newsTwo.title}}</h2>

                          </div>
                      </div>

                      <div class="card">

                          <div class="item item-thumbnail-left item-text-wrap" ui-sref="app.newsdetails({id: newsThree._id})">
                               <img ng-src="{{newsThree.image}}" alt="{{newsThree.image}}">
                              <h2>{{newsThree.title}}</h2>

                          </div>
                      </div>
                  </ion-content>
                </ion-view>

但是当我点击其中任何一个时,我都会收到此问题标题中描述的错误。我该如何解决这个错误?

谢谢, 西奥。

0 个答案:

没有答案