简体   繁体   English

如何在angularjs中将参数从视图传递到控制器

[英]how to pass parameter from view to controller in angularjs

In my controller I have this function: 在我的控制器中我有这个功能:

$scope.add = function(key){
   $scope.key = key;
};

And this is my html view: 这是我的HTML视图:

 <button type="button" ng-click="addVote({{key}});">Confirm</button>

My question is about the ng-click="addVote({{key}}) . I want to call the $scope.key value in my view. It doesn't work. What the mistake I did? 我的问题是关于ng-click="addVote({{key}}) 。我想在我的视图中调用$scope.key值。它不起作用。我做错了什么?

删除{{}}并发送简单对象

ng-click="addVote(key)"

You don't need to perform any interpolation in attributes such as ng-click. 您不需要在ng-click等属性中执行任何插值。 So your code should be as follows: 所以你的代码应该如下:

<button type="button" ng-click="addVote(key);">Confirm</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM