0

Not sure how to do this, but I would like to pass a string as an argument into ng-click and then us it as a conditional in the function. so something like this?

<div class="row">
    <div class="col-md-12 text-center mb-5">
        <div class="btn-group">
            <button class="btn btn-primary" ng-click=""><span class="ion-plus-circled mr-2"></span>New</button>
            <button class="btn btn-outline-primary" ng-click="filter_emails('inbox')"><span class="ion-archive mr-2"></span>Inbox</button>
            <button class="btn btn-outline-primary" ng-click=""><span class="ion-paper-airplane align-middle mr-2"></span>Shielded</button>
        </div>
    </div>
</div>

and then in my controller:

$scope.filter_emails = function(category) {
    if (category == "inbox") {
        $scope.grouped = group(inbox($scope.emails));
    }
    else {
        $scope.grouped = group($scope.emails);
    }
}

This is not working or I obviously wouldn't be posting the question, so what would the correct approach to this?

1
  • this is definitely functioning correctly in this plunker: plnkr.co/edit/7nJbExQv3La9Ka8KZSrs?p=preview (all I changed is adding console.log). This isn't a problem with this function; if you are having issues, it's likely in your group function instead. Commented Nov 8, 2017 at 18:28

1 Answer 1

1

If you want to pass a string enclose it within quotes

ng-click="filter_emails('inbox')"
Sign up to request clarification or add additional context in comments.

7 Comments

I updated my code above, this is not working even with the quotes
try with if (category === "inbox") {
can you create a plunker
working on a full code, but having trouble with plunker getting angular-route.min.js
ok i have a working plunker now. sorry it took me a minutes plnkr.co/edit/MT0182RTJWbqKLeqdODS?p=preview
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.