2016-12-31 4 views
1

Ich möchte einen Wert von Angular an eine Javascript-Funktion übergeben. Winkel Code, um das Element zu machen ist:übergeben Sie einen Wert an JavaScript-Funktion aus Winkel js

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

Dies korrekt den HTML-Code-Taste kehrt als

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

aber wenn ich versuche,

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

die Funktion mit diesem param als

zu nennen });

Das gibt mir die Ausgabe auf der Konsole als

{{patient.id}}--1 

Jede Idee, was bin ich dabei? Dank

+0

Verwenden Sie 'ChatNow (patient.id)' – Tushar

+0

@Tushar, wo sollte ich ändern? Kannst du das bitte illustrieren? Danke – Satya

+0

@Tushar, danke ein Tonne Mann. Du schaukelst !! – Satya

Antwort

1

Versuchen ohne Ausdruck

<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>

0

Versuchen Sie, diese und Konsole 2 für die ID geworfen:

<!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> 
Verwandte Themen