-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ng-click and filter don't work together #4168
Comments
Link that works: |
The problem is that the parser doesn't expect filtered expressions to appear directly in the parameter list.
But it might break other stuff... |
@juhoz1024 why not simply sterilize the input within the controller? Why do you want to be able to apply a filter like that? |
Added a condition to allow the parser to understand whether the parameter is a filter Closes angular#4168
Hello, My use case is a bit strange. I have a mapping of $scope.mapping = {
0: 'zero',
1: 'one',
2: 'two',
}; and I generate a Bootstrap dropdown with one menu item for each <div class="btn-group">
<div class="dropdown">
<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="">Set value <span class="caret"></span></a>
<ul class="dropdown-menu">
<li ng-repeat="(value, name) in mapping"><a href="" ng-click="setValue(value)">{{name}}</a></li>
</ul>
</div>
</div> The problem is that object keys are coerced to To solve the problem, I created an .filter('int', function() {
return function(string) {
return parseInt(string);
};
}) and I'm calling Now I know that a filter that returns a <select class="form-control" ng-model="my.model.value" ng-options="value | int as name for (value, name) in mapping">
<option value=""></option>
</select> and as you can see, the comprehension permits filter chains, not just plain expressions. Really nice. And another thing, I've noticed that I also found From my experience with top-down recursive look-ahead parsers, no other stuff would break with your proposed fix. I'm not a hundred percent sure, but I don't think the grammar would allow for any ambiguities that would break previously correct expressions. So, to sum it up. I know that my use case is strange, but I've shown that there are other "strange" use cases that are already possible, and I think there's no real danger of breaking existing code. So, if it's not too much trouble, please create a pull request with your proposed modification, if not, I could create one myself, but I've just created my github account and I'm pretty sure it would take me significantly more time to do so. Thanks, |
Thanks @esarbanis. Regarding your first commit, the parser can already handle a parenthesized filter expression, because Thank you very much @esarbanis, I haven't really considered that you also have to submit tests, you saved me a lot of work:) @thebigredgeek, see the example with |
@juhoz1024 My first commit was simply ... dump. I hope the second one works for you :) |
Of course a simple workaround would be to put your "filter" function on the scope as:
then you can do:
|
@petebacondarwin, actually the comprehension in ng-options does accept a filter expression, so <select class="form-control" ng-model="my.model.value" ng-options="value | int as name for (value, name) in mapping">
<option value=""></option>
</select> is perfectly valid and works as expected. For $scope.int = $filter('int'); and do |
Right OK, either works in an ngOptions comprehension, but my suggestion On 27 September 2013 14:52, juhoz1024 [email protected] wrote:
|
Added a condition to allow the parser to understand whether the parameter is a filter Closes angular#4168
Added a condition to allow the parser to understand whether the parameter is a filter Closes angular#4168
Added a condition to allow the parser to understand whether the parameter is a filter Closes angular#4168
Could someone review the PR, it's been open for ages. |
i have same problem, i can't get data binding for function in ng-click from ng-repeat, any solution? |
+1 |
Thanks to @esarbanis for the original PR that got out-dated due to the big $parse overhaul. Closes #4175 Closes #4168 Closes #14720
Live example: http://jsfiddle.net/joshdmiller/HB7LU/
Error on the second button below. Also tested with v1.2.0-rc2.
The text was updated successfully, but these errors were encountered: