Reputation: 647
I have something like the following that allows me to successfully access a functions parameter:
HTML:
Angular:
$scope.showContent = function(attrs){
$http({
url: attrs,
method: "POST"
})
.success(function (data, status, headers, config) {
$scope.my_content = data;
})
.error(function (data, status, headers, config) { $scope.status = status; });
};
But what if I have more than one parameter? For example:
<div ng-click="showContent('parameter1', 'parameter2')">
I thought I could do something like $scope.param1 = attrs[0]
, etc. but that didn't work. How can I access both parameters?
Upvotes: 0
Views: 51
Reputation: 1881
Declare the function like $scope.showContent = function(p1, p2){
and use them like $scope.param1 = p1
Or use the arguments
object inside your function like $scope.param1 = arguments[0]
The documentation for the arguments
object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments
Upvotes: 2