0

I try to create custom filter on the 2nd input, first input takes string, second lowercase it and gets rid of spaces

<input placeholder="Name" ng-model="GrCtrl.name" type="text"/>
<input placeholder="CodeName" ng-model="GrCtrl.name | formatToCode" type="text"/>

and here is the filter:

        .controller("controller", function(){
          var self = this;
          self.cloneUserGroup_name = 'Here We Go';
        })
        .filter("formatToCode", function(){
        return function(input){
            return input.toLowerCase().replace(/\s+/g, '');
        }
        });

thou when I run it, it throws the error

Error: [ngModel:nonassign] Expression 'GrCtrl.code_name | formatToCode' is non-assignable.

  • You can't put a filter on an input box. What are you trying to accomplish? – azium Jun 01 '15 at 21:20
  • 1
    Duplicate - http://stackoverflow.com/questions/14419651/filters-on-ng-model-in-an-input – ShankarSangoli Jun 01 '15 at 21:21
  • Unlike a typical interpolated value `{{something}}`, `ng-model` works in both ways: model->view and view->model. Which way do you want to "filter"? You can, in fact, do so with `$formatters` (for model->view) and with `$parsers` (for view->model). See [`ngModelController`](https://docs.angularjs.org/api/ng/type/ngModel.NgModelController) for more reference. – New Dev Jun 02 '15 at 05:00

0 Answers0