Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I want to pass a value from Angular to a Javascript function. Angular code to render the element is:

<button class="btn btn-danger" ng-click="chatNow('{{patient.id}}');">Chat </button>

This correctly returns the HTML of button as

<button class="btn btn-danger" ng-click="chatNow('patient2');">Chat </button>

However, when I try to call the function with this param as

app.controller("VCController",function ($scope, $http,$window){
var t = $scope;
    t.chatNow = function(k) {
            console.log(k + "--"+$window.sessionStorage.getItem("docId"));
        };

});

This gives me the output on console as

{{patient.id}}--1

Any idea what am I missing? Thanks

share|improve this question
    
Use chatNow(patient.id) – Tushar yesterday
    
@Tushar , where should I change? Can you please illustrate. Thanks – Satya yesterday
    
@Tushar , thanks a ton man. You rock!! – Satya yesterday
up vote 1 down vote accepted

Try without expression

<button class="btn btn-danger" ng-click="chatNow(patient.id);">Chat </button>

DEMO

var app = angular.module('DemoApp', [])
app.controller('VCController', function($scope) {
  
 var t = $scope;
 t.patient ={id:1};
  t.chatNow = function(k) {
         console.log(k + "--");
 };
 
});
<!DOCTYPE html>
<html>
<head>
  <script data-require="[email protected]" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script>
 </head>
<body ng-app="DemoApp" ng-controller="VCController">
 <button class="btn btn-danger" ng-click="chatNow(patient.id);">Chat </button>
</body>
</html>

share|improve this answer

Try this and console will thrown 2 for the id:

<!DOCTYPE html>
<html>
<head>
    <title>Hello World, AngularJS - ViralPatel.net</title>
    <script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
    <script>
    angular.module('app',[])
    .controller("VCController",function ($scope, $http,$window){

        var t = $scope;
        $scope.patient = {id: 2};
        t.chatNow = function(k) {
            console.log(k + "--"+$window.sessionStorage.getItem("docId"));

            };
    });
    </script>
</head>
<body>

<div ng-app="app">
    <div ng-controller="VCController">
        <button class="btn btn-danger" ng-click="chatNow(patient.id);">Chat </button>
    </div>
</div>


</body>
</html>
share|improve this answer

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.