从angular js向javascript函数传递一个值

从angular js向javascript函数传递一个值,javascript,angularjs,Javascript,Angularjs,我想将一个值从Angular传递给Javascript函数。渲染元素的角度代码为: <button class="btn btn-danger" ng-click="chatNow('{{patient.id}}');">Chat </button> })) 这给了我控制台上的输出 {{patient.id}}--1 你知道我错过了什么吗?谢谢请不要带任何表情 <button class="btn btn-danger" ng-click="chatNow(pa

我想将一个值从Angular传递给Javascript函数。渲染元素的角度代码为:

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

这给了我控制台上的输出

{{patient.id}}--1
你知道我错过了什么吗?谢谢

请不要带任何表情

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

聊天

尝试此操作,console将为id抛出2:

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

世界你好,AngularJS-ViralPatel.net
角度.module('app',[])
.controller(“VCController”,函数($scope、$http、$window){
var t=$scope;
$scope.patient={id:2};
t、 chatNow=函数(k){
console.log(k+“--”+$window.sessionStorage.getItem(“docId”));
};
});
聊天

使用
chatNow(patient.id)
@Tushar,我应该在哪里换车?你能举例说明吗。Thanks@Tushar,非常感谢。你太棒了!!
<button class="btn btn-danger" ng-click="chatNow(patient.id);">Chat </button>
<!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>