W
W
Whitefoot2015-08-04 09:37:01
Angular
Whitefoot, 2015-08-04 09:37:01

How to dynamically copy the value of a field in AngularJS to another field with a filter?

Good afternoon. There is such task:
The user enters value into a text box. The field is described by the $scope.field model.
The value of the other field is updated dynamically, with the value of $scope.field_t updated and the filter somefilter applied. In this case, you cannot use hard bindings to model properties, because the fields can be different, and this behavior is specified in the template.
For example like this:

<input name="master" type="text" ng-model="$socpe.field" />
<input name="slave" type="text" ng-model="$socpe.field_t" />

It would be cool if you could write like this, but this is not a valid expression for ng-model:
<input name="master" type="text" ng-model="$socpe.field" />
<input name="slave" type="text" ng-model="$socpe.field_t = $socpe.field | somefilter" />

Is there any more or less elegant solution to this problem? Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2015-08-04
@miraage

The logic should not be stored in the template.
Use directives.

S
Sergey, 2015-08-04
Protko @Fesor

filter in the controller by property change and write to another, or make a directive that will add its own formatter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question