共享控制器内的页面特定控制器逻辑

时间:2014-01-14 14:05:43

标签: javascript angularjs

我有一个处理可分页面的控制器,用于许多不同的页面。在网格的标记内,我有时会执行特定于页面的功能,例如:

<table ng-controller="GridCtrl">
    <thead grid-columns pager-info="pagerInfo" onsort="onSort">
        <tr>
            ...
        </tr>
    </thead>
    <tbody>
        <trng-repeat="item in items">
            <td>{{item.x}}</td>
            <td>{{item.y}}</td>
            <td>
                <a href="{{formatLink(item.x, item.y)}}"" class="icon" title="Reply"><i class="ss-icon icon-reply">&#x21A9;</i></a>
            </td>
        </tr>
    </tbody>
</table>

在这个简单的示例中,我想调用一个函数,使用td格式化第三个formatLink单元格中显示的链接。但是,我不想将formatLink添加到我的网格控制器,因为它仅在此页面上使用。

是否有一个共同的角度模式来解决这样的问题?到目前为止我一直在做的是在我的表格中创建一个新的控制器,并将该函数添加到该控制器,以便它可以在需要时使用主网格控制器上的方法。

由于

1 个答案:

答案 0 :(得分:0)

您是否考虑过以其他方式嵌套它们?并将网格控制器作为子控制器?

相关问题