1

I am trying to combine 3 inputs of input text and binding the data to another input text.

<input type="text" class="textbox" name="country" id="loc_country" value="Gershon" ng-model="location.country"/>
<input type="text" class="textbox" name="city" id="loc_city" ng-model="location.city"/>
<input type="text" class="textbox" name="street" id="loc_street" autocomplete="off" ng-model="location.street"/>
<input type="text" class="textbox" name="result" id="result"/>

Here the first 3 inputs need to added to the 4 input automatically with binding

3
  • why the third one is an input box? Do you really need two way binding here? Commented Jul 10, 2015 at 5:31
  • Have you try this ng-model="location.address=location.country+' ' +location.city+' '+location.street'' in 4th input ? Commented Jul 10, 2015 at 5:43
  • Rebornix, the fourth input is inside google map input auto complete, so for your question, yes :). Commented Jul 10, 2015 at 6:15

2 Answers 2

1

You should set the value HTML attribute of the text box. You can do it inline like so:

<input type="text" class="textbox" name="result" id="result" value="{{location.street + ' ' + location.city + ' ' + location.country}}"/>

Or you can use a computed property. Here is an example:

HTML:

<div ng-app>
  <div ng-controller="SomeCtrl">
      <input ng-model="textProperty"/>
      <input value="{{getCalculatedText()}}"/>             
  </div>
</div>

JS:

function SomeCtrl($scope) {
  $scope.textProperty = "some text";
  $scope.getCalculatedText = function() {
    return $scope.textProperty+ " is now calculated";};
  }
Sign up to request clarification or add additional context in comments.

Comments

0

Please see my example answer here: https://jsfiddle.net/em0ney/bc3chrog/2/

function ExampleController($scope) {
    $scope.location = {country: 'Australia', city: 'Sydney', street: 'Pitt St'};
    $scope.concatLocationComponents = function() {
        return $scope.location.street + ' ' + $scope.location.city + ', ' + $scope.location.country;
    };
}

Good luck with formatting the result.

Thanks, Elliott

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.