Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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?

share|improve this question
up vote 2 down vote accepted

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>

share|improve this answer
    
Thanks! I tried initially to do toString methog as well but I must've done it incorrectly. This did it. – VolcovMeter Jul 23 at 21:35
    
Glad to help :) – developer033 Jul 23 at 21:38
    
yea sorry, was waiting for the timer to allow me to do so :) – VolcovMeter Jul 23 at 21:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.