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?

asked Apr 2, 2015 at 16:16

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.

answered Apr 2, 2015 at 16:19
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>
answered Apr 2, 2015 at 16:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.