0

Say for example I have an element like this:

<input type="button" id="model{{id}}{{Value}}" ng-click="myFunction(     )">

if id was 178 and Value was 123, how can I make the ng-click above concatenate those value and pass them into the function?

Simply by going ng-click=myFunction(id + Value) would return a sum, when I would want the value passed into that function to be 178123.

This possible?

1 Answer 1

2

Simple, use the Number.prototype.toString() method:

<input type="button" id="model{{id}}{{Value}}" ng-click="myFunction(id.toString() + Value.toString())">

Simple demo:

(function() {
  angular
    .module('app', [])
    .controller('mainCtrl', mainCtrl);

  function mainCtrl($scope) {
    $scope.id = 178;
    $scope.Value = 123;
    
    $scope.myFunction = function(value) {
      console.log(value);
    }
  }
})();
<!DOCTYPE html>
<html ng-app="app">

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>

<body ng-controller="mainCtrl">
  <input type="button" id="model{{id}}{{Value}}" ng-click="myFunction(id.toString() + Value.toString())" value="Click">
</body>

</html>

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I tried initially to do toString methog as well but I must've done it incorrectly. This did it.
yea sorry, was waiting for the timer to allow me to do so :)

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.