VolcovMeter VolcovMeter - 1 year ago 108
AngularJS Question

AngularJS: How to pass in multiple INT values as string from ng-click?

Say for example I have an element like this:

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

was 178 and
was 123, how can I make the
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?

Answer Source

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

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

Simple demo:

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

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

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

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download