If you're looking for a better approach, you might want to try something along these lines:
Solution
<input ng-model="first">
<input ng-model="second">
<span>{{result}}</span>
Approach
$scope.$watchCollection("[first,second]", function(newVals){
$scope.result = newVals[0] + " and " + newVals[1];
});
Now you can easily access the result with var myResult = $scope.result
. Check out this live example. It's worth noting that ngModel
typically works best with inputs. According to the documentation:
The ngModel directive binds an input, select, textarea (or custom form control) to a property on the scope using NgModelController, which is created and exposed by this directive.
Consider creating your own directive if needed, or exploring alternative strategies before proceeding further with your current approach.