2

我使用 angularjs 1.0.7 并尝试将 ng-click 处理程序添加到使用 ng-repeat 重复的列表元素,但该函数不会触发。下面是 html,以及我在评论中尝试过的变体。我尝试在不同的元素上添加相同的 ng-click 功能,它工作正常。

<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>

这是控制器

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);

    };

});
4

1 回答 1

2

您的标记中有错误,您在控制器中的函数被调用getPlayList,并且在您的标记中它的getPlaylist. 注意l. 这是一个固定的小提琴,没​​有问题:http: //jsfiddle.net/GYatesIII/z7mpW/3/

于 2013-08-07T23:23:40.270 回答