0

I have this basic fiddle which is a cut down version of what I have on my site.

I was wondering if there is a way to bind the table rows dynamically to a text area to create a ng-model composed of serveral other ng-model data?

I would like to to have each line in a list or something which I could then add additional text to from a text input element and have that all bound to a text area. Changes to either would be reflected in the form preview.

Is this possible?

3
  • Curious what use case is. Is it to paste existing data in or to generate data to copy from? Approach to doing this would be different for each case Commented May 13, 2015 at 2:22
  • To convert it into a sort of forum post to include a reason for requesting the items. I'm not sure if there is a better way of going about it. Commented May 13, 2015 at 2:23
  • Not sure I follow that explanation. Commented May 13, 2015 at 2:25

1 Answer 1

1

First, there was a tiny mistake in your fiddle, requestQty should be an object indexed by itemId, or an array where the index is the item id, but as is it is a mix of both.

Now regarding your question, you could indeed keep a binding between a textarea and your model, bu not directly with ng-model since the textarea deals with a string, and your data is object.

One way to work around that is having two different variables, a model object and a stringModel string, and keep both synchronized using custom $watchers.

You can see an implementation of that solution here:

http://jsfiddle.net/dscace5q/1/

$scope.$watch('model', function(m) {
    $scope.stringModel = angular.toJson(m, 2);
}, true);

$scope.$watch('stringModel', function(s) {
    $scope.model = angular.fromJson(s);      
});
Sign up to request clarification or add additional context in comments.

Comments

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.