我想将值从 Angular 传递到 Javascript 函数。渲染元素的 Angular 代码是:
<button class="btn btn-danger" ng-click="chatNow('{{patient.id}}');">Chat </button>
这会正确返回按钮的 HTML
<button class="btn btn-danger" ng-click="chatNow('patient2');">Chat </button>
但是,当我尝试使用此参数调用该函数时
app.controller("VCController",function ($scope, $http,$window){
var t = $scope;
t.chatNow = function(k) {
console.log(k + "--"+$window.sessionStorage.getItem("docId"));
};
});
这给了我控制台上的输出
{{patient.id}}--1
知道我错过了什么吗?谢谢
最佳答案
尝试不表达
<button class="btn btn-danger" ng-click="chatNow(patient.id);">Chat </button>
演示
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="angular.js@1.4.7" 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>
关于javascript - 将值从 Angular JS 传递给 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41405855/