Using ui-router
I have a parent view called current-transactions
in which a table is populated with data, and when a user clicks on a tr
it displays further information of the selected transaction, in a child state called current-transactions-item
.
In the table, in the parent view, there is a drop-down which I want to use as a filter for the items that are displayed in the child view. So one transaction can have multiple items, and if a user selects order number foo123
I want the only that item to display. When I insert an text input
into the same view as the displayed results, the items are filtered, but when I insert the input
into the parent state, which it needs to be, it fails to filter the results.
<input type="text" name="test" ng-model="testFilter">
<div ui-view></div> //child state where the results are, fails to be filtered
I don't know if I am missing something simple, but I don't know whether to create a custom filter, function, directive etc.
I am using ui-router
to route my app, and Angular's components
to structure it.
Question
How do I filter results in a child state from an input within a parent state?
.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
Found a solution and have left my answer. I used $watch
to look for changes in the parent scope. If anyone else has another method of solving this issue, feel free to leave an answer.