Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to AngularJS, and I got stuck on this ng-click when trying to set some parameters before uploading an image. Here is the code:

<div ng-controller="TestCtrl">
    <div data-ng-click="readUploadedImage('grPhoto', '{{ id }}')">
        <label class="changePhotoBtn" for="uploadBanner">Click Here</label>
        <input style="display: none;" type="file" name="Upload a file" id="uploadBanner" />
    </div>
</div>

var myApp = angular.module('myApp',[]);

function TestCtrl($scope) {
    $scope.id = 1234;

    $scope.readUploadedImage = function(parentClass, spid) {       
        alert(parentClass + ' ' + spid);
    }
}

Link to Fiddle: http://jsfiddle.net/CMJkg/2/

share|improve this question
    
What exactly does not work? –  Sprottenwels Oct 15 '13 at 13:19
    
Rename function TestCtrl($scope) to function MyCtrl($scope) –  Dhaval Marthak Oct 15 '13 at 13:19
    
Sorry for the naming error. The problem is it never gets to the alert(). So the method called in ng-click never gets fired. –  Ioana Cucuruzan Oct 15 '13 at 13:23

1 Answer 1

up vote 1 down vote accepted

Change readUploadedImage('grPhoto', '{{ id }}') to readUploadedImage('grPhoto', id). Expressions in ng-click are evaluated.

Demo here.

share|improve this answer
    
Thank you, that works. –  Ioana Cucuruzan Oct 15 '13 at 13:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.