如何根据stateParams显示页面的一部分?

时间:2017-07-28 22:35:26

标签: angularjs angular-ui-router

我有一个包含多行的表格,每一行都有一个<td>ID

&#13;
&#13;
<table>
    <thead>
        <tr>
            <th>
               ID
            </th>
            <th>
               XYZ
            </th>
            <th>
               XYZ
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <a href="">10</a>
            </td>
            <td>
                XYZ
            </td>
            <td>
                XYZ
            </td>
        </tr>
        <tr colspan="3" class="more-info">
            <!-- I want to show this row if the $stateparams has an id === 10;  -->
        </tr>
        <tr>
            <td>
                <a href="">120</a>
            </td>
            <td>
                XYZ
            </td>
            <td>
                XYZ
            </td>
        </tr>
        <tr colspan="3" class="more-info">
            <!-- I want to show this row if the $stateparams has an id === 120;  -->
        </tr>
        <tr>
            <td>
                <a href="">420</a>
            </td>
            <td>
                XYZ
            </td>

            <td>
                XYZ
            </td>
        </tr>
        <tr colspan="3" class="more-info">
                        <!-- I want to show this row if the $stateparams has an id === 420;  -->
        </tr>
    </tbody>
</table
&#13;
&#13;
&#13;

当您点击ID时,会向服务器发送请求以获取ID的数据。数据将显示在行ID行下方的表格行中。点击还会更新url,例如从localhost:3000/app更新为localhost:3000/app/420

如何仅显示与table row匹配的行下方的stateparams.id?如果您刷新页面(localhost:3000/app/420),它仍应显示。

提前致谢!

1 个答案:

答案 0 :(得分:1)

你可以这样做:

在Html中:

   <tr colspan="3" class="more-info" ng-if="CurrentID=='120'">
     <!-- I want to show this row if the $stateparams has an id === 120;  -->
  </tr>

在JS中

    app.controller("myCtrl", function($scope,$stateParams) {

       $scope.CurrentID = 0;

      if($stateParams.id != undefined){

           $scope.CurrentID = $stateParams.id;

       }

    });