1

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/

3
  • What exactly does not work? Commented Oct 15, 2013 at 13:19
  • Rename function TestCtrl($scope) to function MyCtrl($scope) Commented Oct 15, 2013 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. Commented Oct 15, 2013 at 13:23

1 Answer 1

1

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

Demo here.

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

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.