0

Having this js fiddle

var app = angular.module('myApp', []);

app.controller('MyController', ['$scope', MyController]);    

function MyController($scope) {

    $scope.value1 = $scope.value1;
    $scope.value2 = "this is it: " + $scope.value1;
}
<html>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">

</script>
<div ng-controller='MyController'>
    <h1>Introduce your value:</h1>
    <input type="text" ng-model="value1"></input></br>
    <input type="text" ng-model="name" ng-change="value1"></input>
</div>
</html>

I want to introduce a value in the first input and to get it into the next one as "this is it: firstvalue".

2
  • have you loaded angular.js library in you html? Commented Mar 28, 2018 at 20:18
  • @HiteshKansagara sorry, forgot about that. I added it now Commented Mar 28, 2018 at 20:21

1 Answer 1

1

You can achieve that easily using ng-change and using ng-model properly

var app = angular.module('myApp', []);

app.controller('MyController', ['$scope', MyController]);    

function MyController($scope) {

    $scope.value1 = undefined;
    $scope.value2 = undefined;
    
    $scope.onValue1Change = function(){
      $scope.value2 = "this is it: " + $scope.value1;
    };
}
<html ng-app="myApp">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
</script>
<div ng-controller='MyController'>
    <h1>Introduce your value:</h1>
    <input type="text" ng-model="value1" ng-change="onValue1Change()"></input></br>
    <input type="text" ng-model="value2"></input>
</div>
</html>

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.