AngularJS Display 1 Post in New Page

后端 未结 2 1655
孤城傲影
孤城傲影 2021-01-26 12:03

I want to display only Test Post 1 in next html page titleDetails.html when user clicks Test Post 1 in index.html

相关标签:
2条回答
  • 2021-01-26 12:58

    a new scope variable in BlogController

    $scope.postDetail = null;
    

    and method titleDetails() be like

    $scope.titleDetails = function(post) {
    $scope.postDetail = post;
    }
    

    and also make change in index.html

     <a  ng-click="titleDetails(post)">{{ post.title }} </a>
    
    0 讨论(0)
  • 2021-01-26 13:03

    Hope this following steps work for you
    Pass post object to titleDetail() function.
    In index.html

    <a  ng-click="titleDetails(post)">{{ post.title }} </a>
    

    In function assign post to $rootScope variable

    $scope.titleDetails = function(post) {
       $rootScope.postDetail = post;
    }
    

    Now your titleDetail.html page controller:

    $scope.post = $rootScope.postDetail;
    
    0 讨论(0)
提交回复
热议问题