AngularJs和Laravel使用嵌套路由

时间:2015-01-22 21:07:12

标签: angularjs laravel routes nested

我是angularjs的新手,我不知道如何使用嵌套路线。

在我的Laravel路线文件中,我设置了一条像movie{id}/review{id}这样的路线,我需要用角度来安静地工作。

问题是我为所有电影做了一个循环然后用于所有评论,在PHP中这很简单,但是使用Angular我无法在评论循环中访问电影的id。

我为Laravel和Angular设置了不同的电影和评论控制器。

这是angular的html部分,请注意我使用modal创建和编辑表单。

<div class="row" ng-app="movies" ng-controller="moviesController">

    <h2>All movies</h2>
    <div ng-repeat="movie in movies" ng-init="movId = movie.id">
        <blockquote>
            <strong class="text-center "><% movie.title %></strong>
            <p><% movie.description %></p>
            {{--<footer><% movie.review %></footer>--}}
        </blockquote>
        <div class="clearfix"></div>
        <button type="button" class="btn btn-primary btn-sm" ng-click="editMovie(movie.id)">
            Edit Movie
        </button>
        <button type="button" class="btn btn-primary btn-sm" ng-click="deleteMovie(movie.id)">
            Delete Movie
        </button>
        <div ng-controller="moviesReviewController">
            <div ng-repeat="movieReview in movieReviews">
                <blockquote>
                    <strong class="text-center "><% movieReview.title %></strong>
                    <p><% movieReview.body %></p>
                    <footer><% movieReview.stars %></footer>
                </blockquote>
                <button type="button" class="btn btn-primary btn-sm" ng-click="editMovieReview(movId, movieReview.id)">
                    Edit Movie
                </button>
                <button type="button" class="btn btn-primary btn-sm" ng-click="deleteMovieReview(movId, movieReview.id)">
                    Delete Movie
                </button>
            </div>
            <button type="button" class="btn btn-primary" data-toggle="modal" ng-click="movieId = movId" data-target="#movieReviewModal">
                Post a review
            </button>
        </div>
    </div>
    <p class="text-center" ng-show="loading"><span class="fa fa-meh-o fa-5x fa-spin"></span></p>
    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#moviesModal">
        Add New Movie
    </button>

0 个答案:

没有答案