使用ui-router
我有一个父视图称为current-transactions
其中一个表被填充数据,并且当一个用户点击一个tr
它显示所选择的交易的详细信息,在子状态称为current-transactions-item
。访问子状态以筛选结果
在表中,在父视图中,有一个下拉列表,我想用它作为筛选器显示在子视图中的项目。所以一个交易可以有多个项目,如果用户选择订单号码foo123
我希望只显示该项目。当我将text input
插入与显示结果相同的视图中时,项目会被过滤,但是当我将input
插入到它所需的父状态时,它无法过滤结果。
<input type="text" name="test" ng-model="testFilter">
<div ui-view></div> //child state where the results are, fails to be filtered
我不知道如果我失去了一些东西简单,但我不知道是否要创建一个自定义过滤器,函数,指令等
我使用ui-router
路由我的应用程序,和Angular的components
来构造它。
问题
如何从父州内的输入滤波器在子状态的结果吗?
.state('current-transactions', {
url: '/current-transactions',
component: 'currentTransactions',
})
.state('current-transactions.current-transaction-item', {
url: '/{transId}',
component: 'currentTransaction',
})
//parent state
<input type="text" name="test" ng-model="testFilter">
<div ui-view></div>
//child state
<div ng-repeat="transaction in $ctrl.patents | filter: testFilter">
//data from ng-repeat displayed
</div>
UPDATE
找到了解决方案,并已离开我的答案。我使用$watch
来查找父范围中的更改。如果其他人有解决这个问题的另一种方法,请随时留下答案。
你试过访问与'$ parent'父? –
在过滤器中您的意思是? –
使用服务在控制器/状态之间共享'testFilter'。 –