1

I'm new to angular.js. Below is my first working app. The second text area displays the text typed in the first area. What's the proper way and how to make it work this way: the text result is almost the same as in the source, but letters "a" are replaced with "0".

<!DOCTYPE html>
<html data-ng-app="">
<head>
    <script src="angular1.2.12.js"/>
    <script>
    </script>
</head>
<body>
    <textarea data-ng-model="source"></textarea>
    <textarea id="result">{{source}}</textarea>
</body>
</html>

Here is a jsFiddle.

2
  • I could edit your Jsfiddle to do what you want to achieve. However, i believe that this won't help you as it would be the shortest possible way to do so and has nothing to do with a 'real world' application. What have you tried so far? Have you completed the tutorial? Commented Feb 10, 2014 at 9:56
  • Just started. Thank you. Commented Feb 10, 2014 at 15:15

1 Answer 1

1

You can have a filter applied to the source to do the conversion.

app.filter('replaceA', function(){
    return function(input){
      return input.replace(new RegExp('a', 'g'), '0');
    }
});

Then apply this to your HTML

<textarea data-ng-model="source"></textarea>
<textarea id="result">{{ source || '' | replaceA }}</textarea>

jsFiddle

Sign up to request clarification or add additional context in comments.

1 Comment

JS replace() will only replace the first occurrence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.