I have a textbox who's value is bound to $scope.stringOne
in my controller. I then have a second variable, $scope.stringTwo
which is a concatenation of stringOne
and more text.
However, when I type in the textbox, stringOne
is successfully updated in the View, but stringTwo
remains unchanged.
What else is needed to make this work, so that the stringTwo
value is also updated when stringOne
is updated?
HTML
<body ng-controller="mainCtrl">
<div class="container">
<label>Enter Text</label>
<input type="text" ng-model="stringOne"/>
<h1>{{stringOne}}</h1>
<h1>{{stringTwo}}</h1>
</div>
</body>
JS
var myApp = angular.module('myApp',[]);
myApp.controller('mainCtrl',['$scope',function ($scope,) {
$scope.stringOne = '';
$scope.stringTwo = $scope.stringOne + ' more texts';
}]);