angularjs - Angular: further dynamic filtering issue -
i'm trying these dynamic filters working , there think. looks model isn't being passed watch function. would've expected work first set of filters @ least doesn't.
what i'm trying achieve when user selects option select list , sets value in input box data filtered. user can optionally add set of filters clicking "add fields" button. if there user completes second set of filters data filtered further.
this i've got far. if there's 1 filter showing shouldn't work?
this code creates user defined filters.
<div data-ng-repeat="filter in filters"> <select ng-model="filter.id"> <option value="age">age</option> <option value="customerid">customerid</option> <option value="productid">productid</option> <option value="name">name</option> </select> <input type="text" ng-model="data.search[filter.id]"> <button class="remove" ng-show="$last" ng-click="removefilter()">-</button>
add fields
i think i'm there, got better understanding of hierarchical scope. i've referred few tutorial , examples i'm not quite there yet. think issue i'm not communicating models properly. still little bit lost this. further tips/suggestions great. i'm wondering if should move of code controller in directive resultsctrl
controller. not sure.
this fiddle gave me idea use filter.id
within template ng-repeat
this plnkr helpful.
i'm getting somewhere now. this plnkr shows working, last thing want when remove filter automatically updates search object remove relevant filter.
any suggestions on how this?
you breaking golden rule of "always have dot in ng-model
".
why? because objects have inheritance , primitives not.
ng-model="filtertype"
is being defined inside child scope created ng-repeat
. because primitive parent scope in controller can not see it. if property of object available @ parent level, reference shared between parent , child.
once fix bug run bug scope.search
not object either $watch function throw exception also. in main controller can set:
$scope.search ={};
do reading on how hierarchical scopes work in angular. there plenty found in web searches , angular docs
Comments
Post a Comment