使用Angular.js'ng-repeat创建动态链接

时间:2016-09-08 05:47:57

标签: javascript angularjs dynamic angularjs-ng-repeat dynamic-linking

我正在使用假JSONplaceholder API创建一个应用。我正在显示帖子列表,我希望ng重复的帖子标题链接到帖子视图。

这是HTML:

    <body layout="column" ng-app="myApp" ng-cloak ng-controller="controller">
    <h1>{{apptitle}}</h1>
    <script type="text/ng-template" id="allposts.htm">
        <a href="#addpost">
    <button type="button" class="btn btn-primary addbtn" ng-model="singleModel" uib-btn-checkbox btn-checkbox-true="1" btn-checkbox-false="0">
        Add a post
    </button>
</a>
        View
        <select ng-model="viewby" ng-change="setItemsPerPage(viewby)">
            <option>9</option>
            <option>18</option>
            <option>36</option>
            <option>100</option>
        </select>posts
        <div class="row" ng-repeat="collatedPostList in collatedPosts">
            <div class="onepost col-xs-4 box" ng-repeat="post in collatedPostList">
                 <div class="inner">
                <a href="#/posts/{{post.indexOf(post)}}">{{post.title}}</a>
                <p>{{post.body | limitTo: 60}}{{post.body.length < 20 ? '' : '...'}}</p>
            </div>
            </div>
        </div>
        <div class="text-center">
        <ul uib-pagination total-items="totalItems" ng-model="currentPage" class="pagination-sm"
            items-per-page="itemsPerPage" ng-change="pageChanged(currentPage)"></ul>
        </div>
    </script>
    <script type="text/ng-template" id="posts.htm">
  </script>
    <script type="text/ng-template" id="addpost.htm">
    <form ng-submit="addPost()" class="adding">
        <input id="titleadd" type="text" name="title" ng-model="newPost.title" placeholder="Add title">
        <br>
        <input id="textadd" type="text" name="body" ng-model="newPost.body" placeholder="Add some text">
        <br>
        <button type="submit" ng-click="addAlert(msg,'success')" class="btn btn-primary" id="submit" value="Submit">
        Post it
        </button>
        <a href="#allposts">
        <button type="button" class="btn btn-primary" >
            Go back to post list
        </button></a>
            <br>
        <uib-alert 
              ng-repeat="alert in alerts" 
              type="{{alert.type}}" 
              dismiss-on-timeout="5000" 
              close="alerts.splice($index, 1);">{{alert.msg}}
    </uib-alert>    </form>
  </script>
    <div ng-view></div>
    <script src="app.js"></script>
</body>

和JS:

Array.prototype.collate = function(collateSize) {
    var collatedList = [];

    if (collateSize <= 0) {
        return [];
    }
    angular.forEach(this, function(item, index) {
        if (index % collateSize === 0) {
            collatedList[Math.floor(index / collateSize)] = [item];
        } else {
            collatedList[Math.floor(index / collateSize)].push(item);
        }
    });

    return collatedList;
};

var myApp = angular.module('myApp', ['ngRoute', 'ui.bootstrap']);

myApp.config(function($routeProvider) {
    $routeProvider.when('/', {
        templateUrl: 'allposts.htm',
        controller: 'PostsController'
    }).when('/posts', {
        templateUrl: 'posts.htm',
        controller: 'PostController'
    }).when('/addpost', {
        templateUrl: 'addpost.htm',
        controller: 'AddController'
    }).otherwise({
        redirectTo: '/'
    });
});

myApp.controller('PostsController', function($scope) {});

myApp.controller('PostController', function($scope) {});

myApp.controller('AddController', function($scope) {});


myApp.controller('controller', function($scope, $http) {
    $scope.apptitle = "My app";

    $http({
        method: 'GET',
        url: "http://jsonplaceholder.typicode.com/posts"
    }).then(function(response) {
        $scope.posts = response.data;
        $scope.viewby = 9;
        $scope.totalItems = $scope.posts.length;
        $scope.currentPage = 1;
        $scope.itemsPerPage = $scope.viewby;
        $scope.maxSize = 5;
        $scope.collatedPosts = getCollatedPosts($scope.posts);
        $scope.newPost = {};


    function getCollatedPosts(posts) {
        if (!posts) {
            return [];
        }

        var paginatedPosts = posts.slice((($scope.currentPage - 1) * $scope.itemsPerPage), (($scope.currentPage) * $scope.itemsPerPage));
        return paginatedPosts.collate(3);
    }

    $scope.setPage = function(pageNo) {
        $scope.currentPage = pageNo;
    };

    $scope.setItemsPerPage = function(num) {
        $scope.itemsPerPage = num;
        $scope.currentPage = 1; //reset to first page
        $scope.collatedPosts = getCollatedPosts($scope.posts);
    };

    $scope.pageChanged = function(currentPage) {
        $scope.currentPage = currentPage;
        $scope.collatedPosts = getCollatedPosts($scope.posts);
    };
        $scope.addPost = function(){
          $http.post("http://jsonplaceholder.typicode.com/posts",{
            title: $scope.newPost.title,
            body: $scope.newPost.body,
            usrId: 1
          })
          .success(function(data, status, headers, config){
            console.log(data);
            $scope.posts.push($scope.newPost);
            $scope.newPost = {};
          })
          .error(function(error, status, headers, config){
            console.log(error);
          });
    };});


    $scope.alerts = [];

    $scope.msg = "Well done! Your post was added";

    $scope.addAlert = function(msg, type) {
      $scope.alerts.push({
        msg: msg,
        type: type
      });
    };

});

我的代码无效。有100多个重复的帖子,我希望每个帖子标题链接到帖子视图。当前代码将每个标题链接到#/posts。我也试过<a href="#/posts/{{post.id}}">{{post.title}}</a>,但没有成功。 这样做的正确方法是什么?

您可以看到完整代码here

2 个答案:

答案 0 :(得分:1)

首先我写这样的路线提供者:

myApp.config(function($stateProvider, $routeProvider) {
    $routeProvider.otherwise('/posts');

    $stateProvider.state('posts', {
      url: '/posts',
      templateUrl: 'allposts.htm',
      controller: 'PostsController'
    }).state('posts.detail', {
      url: '/:postId',
      templateUrl: 'posts.htm',
      controller: 'PostController'
    }).state('posts.add', {
      url: '/add',
      templateUrl: 'addpost.htm',
      controller: 'AddController'
    });
});

然后,您可以创建链接:

<a ui-sref="posts.detail({postId: post.id})">{{ posts.title }}</a>

答案 1 :(得分:1)

您可以按照以下方式调试代码。

Fatal Exception: android.view.InflateException: Binary XML file line #76: Error inflating class com.mathrusoft.infogo.widget.MySelectView
       at android.view.LayoutInflater.createView(LayoutInflater.java:620)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:36)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:27)
       at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
       at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
       at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
       at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
       at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
       at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
       at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:596)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1091)
       at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:801)
       at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:815)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2007)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1764)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1020)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5762)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
       at android.view.Choreographer.doCallbacks(Choreographer.java:574)
       at android.view.Choreographer.doFrame(Choreographer.java:544)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:149)
       at android.app.ActivityThread.main(ActivityThread.java:5257)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.constructNative(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at android.view.LayoutInflater.createView(LayoutInflater.java:594)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:36)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:27)
       at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
       at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
       at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
       at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
       at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
       at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
       at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:596)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1091)
       at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:801)
       at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:815)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2007)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1764)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1020)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5762)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
       at android.view.Choreographer.doCallbacks(Choreographer.java:574)
       at android.view.Choreographer.doFrame(Choreographer.java:544)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:149)
       at android.app.ActivityThread.main(ActivityThread.java:5257)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by android.content.res.Resources$NotFoundException: File res/drawable/ic_star_24dp.xml from drawable resource ID #0x7f0200c8
       at android.content.res.Resources.loadDrawable(Resources.java:2156)
       at android.content.res.Resources.loadDrawable(Resources.java:2075)
       at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
       at com.mathrusoft.infogo.widget.MySelectView.applyAttributeSet(MySelectView.java:65)
       at com.mathrusoft.infogo.widget.MySelectView.<init>(MySelectView.java:41)
       at java.lang.reflect.Constructor.constructNative(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at android.view.LayoutInflater.createView(LayoutInflater.java:594)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:36)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:27)
       at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
       at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
       at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
       at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
       at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
       at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
       at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:596)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1091)
       at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:801)
       at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:815)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2007)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1764)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1020)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5762)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
       at android.view.Choreographer.doCallbacks(Choreographer.java:574)
       at android.view.Choreographer.doFrame(Choreographer.java:544)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:149)
       at android.app.ActivityThread.main(ActivityThread.java:5257)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
       at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
       at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
       at android.content.res.Resources.loadDrawable(Resources.java:2152)
       at android.content.res.Resources.loadDrawable(Resources.java:2075)
       at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
       at com.mathrusoft.infogo.widget.MySelectView.applyAttributeSet(MySelectView.java:65)
       at com.mathrusoft.infogo.widget.MySelectView.<init>(MySelectView.java:41)
       at java.lang.reflect.Constructor.constructNative(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at android.view.LayoutInflater.createView(LayoutInflater.java:594)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:36)
       at com.mathrusoft.infogo.adapter.AdapterNewsList.onCreateViewHolder(AdapterNewsList.java:27)
       at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
       at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
       at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
       at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
       at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
       at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
       at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:596)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15092)
       at android.view.ViewGroup.layout(ViewGroup.java:4645)
       at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1091)

然后

您可以通过console.log(response.data) // will give you data in success http get 以HTML格式打印这些数据,如果您在那里获得数据,那么您就是在正确的轨道上。

请尝试使用以下代码段链接帖子

{{posts}}
var myApp = angular.module('myApp', []);
myApp.controller('PostController', ['$scope','$http', function($scope, $http) {
  var root = 'http://jsonplaceholder.typicode.com';
  
  $http({
    method: 'GET',
    url: root+'/posts'
  }).then(function successCallback(response) {
     $scope.posts= response.data;
  }, function errorCallback(response) {
    
  });
}]);