0

I have the following html:

<button id="capIt" class="preview" ng-click="saveCaption('{{ user_id }}')">
  <i class="fa fa-floppy-o"></i> Save It!
</button>

Which, when inspected in the DOM, translates to e.g. this:

<button id="capIt" class="preview" ng-click="saveCaption('123')">
  <i class="fa fa-floppy-o"></i> Save It!
</button>

I have a function inside my controller:

capApp.controller('mainController', 
    ['$scope', '$http', '$rootScope', '$location', 
        function($scope, $http, $rootScope, $location) {
          $scope.saveCaption = function(user_id) {
            console.log('clicked '+user_id);
            // plus other stuff but that's irrelevant
          }
  }]);

But when the button is clicked what I see in the console is this:

clicked {{ user_id }}

Why is the code correct in the DOM but the function is getting {{ user_id }} instead of 123?

2 Answers 2

1

Just pass user_id instead of {{user_id}}

Your variable is in scope, so any value will be picked up directly.

Sign up to request clarification or add additional context in comments.

Comments

1

You don't need to scape user id as you are already in "code".

Try:

<button id="capIt" class="preview" ng-click="saveCaption(user_Id)">
   <i class="fa fa-floppy-o"></i> Save It!
</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.