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.

Im using angularjs 1.0.7 and trying to add a ng-click handler to a list element which is repeated using ng-repeat, but the function does not fire. Below is the html, along with variations I have tried in comments. I have tried adding the same ng-click function on a different element and it works fine.

<div class="results" ng-cloak ng-show="showList != 0">

    <ul>
        <li ng-repeat="movie in movies" ng-click="getPlaylist(movie.id)">{{ movie.title }}</li>
        <!--<li ng-repeat="movie in movies" ng-click="getPlaylist({{movie.id}})">{{ movie.title }}</li>-->
        <!--<li ng-repeat="movie in movies" ng-click="getPlaylist('movie.id')">{{ movie.title }}</li>-->
        <!--<li ng-repeat="movie in movies" ng-click="getPlaylist(\'{{movie.id}}\')">{{ movie.title }}</li>-->
    </ul>
</div>

And here is the controller

main.controller('MoviesListCtrl', function($scope, $http, playlist) {

    $scope.movies = [];
    $scope.showList = false;


    $scope.getMoviesList = function (val) {

        var link = 'titles?q=' + val + '&limit=10'

        $http.get(link).success(function (data) {
            // now we have all our movies and can add them
            $scope.movies = data;

            // if there any movies we can show the list
            if ($scope.movies.length > 0) {
                $scope.showList = true;
            } else {
                $scope.showList = false;
            }
        });
    };

    $scope.getPlayList = function (id) {
        alert(id);

    };

});
share|improve this question
 
@RafaelBarros Still not doing anything. –  Errol Fitzgerald Aug 7 '13 at 23:23
add comment

1 Answer

up vote 1 down vote accepted

You have an error in your markup, your function in the controller is called getPlayList and in your markup its getPlaylist. Note the capitalization on the l. Here's a fiddle where it's fixed and there's no problem: http://jsfiddle.net/GYatesIII/z7mpW/3/

share|improve this answer
 
wow, I feel dumb! Thanks for spotting that. –  Errol Fitzgerald Aug 7 '13 at 23:25
 
Happens to the best of us. The only reason a fiddle for it exists is because I didn't catch it for a little bit. –  George Yates Aug 7 '13 at 23:26
3  
In a perfect world, Angular would throw an exception when ng-click makes a call to an undefined function. –  George Yates Aug 7 '13 at 23:28
add comment

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.