我有一个显示产品列表的表。我在“所有产品”页面和“我的产品”页面上显示相同的表格。这是此表的一部分:

<tr ng-repeat="product in products>
  <td>{{product.id}}</td>
  <td>{{product.name}}</td>


“所有产品”和“我的产品”页面都有自己的控制器,可在其中设置$scope.products变量。

我可以排除此特征的定义以分开文件并将其用于“所有产品”和“我的产品”页面吗?

最佳答案

使用ng-include。是的,您可以使用这些内容创建一个table.html文件

或者,您甚至可以创建内联角度模板

<script type="text/ng-template" id="table.html">
    <tr ng-repeat="product in products>
        <td>{{product.id}}</td>
        <td>{{product.name}}</td>
    </tr>
</script>


然后包括您想要的任何地方:

<div ng-include="'table.html'"></div>

07-26 05:25
查看更多