繁体   English   中英

Angular JS路由不起作用

[英]Angular JS routing not working

访问控制器但无法正常工作后,我试图将页面路由到另一个页面。 我可以路由前两页,但第三页不起作用。 有人可以帮我吗

这是我的路由代码:

$routeProvider', function ($routeProvider) {
            $routeProvider.
                when('/category', {
                    //templateUrl : 'js/partials/course-list.html',
                    controller : 'CategoryController'
                }).
                when('/category/:categoryid', {
                    templateUrl : 'js/partials/film-list.html',
                    controller : 'MovieController'
                }).
                when('/actor/:filmid', {
                    templateUrl : 'js/partials/actor-list.html',
                    controller : 'ActorController'
                }).
                otherwise({
                    redirectTo : '/'
                });
        } 

目前,我的ActorController无法正常工作。 一旦我单击电影,它应该显示电影的演员,但对我而言,它不起作用

这是我的movie-list.html的部分html文件。

<section>
<h3>{{movieCount}}</h3>
<table>
    <tr data-ng-repeat="movie in movies" data-ng-click="selectFilm($event,movie)"  style="cursor: pointer;">
        <td>{{movie.title}}</td>
    </tr>
    <strong>{{successMessage}}</strong>
</table>

这是我的控制器代码

).controller('ActorController', 
            [
                '$scope', 
                'dataService', 
                '$routeParams',

                function ($scope, dataService, $routeParams){
                    $scope.actors = [ ];
                    $scope.actorCount = 0;

                    var getActors = function (moviecode) {
                        dataService.getActors(moviecode).then(
                            function (response) {
                                $scope.actorCount = response.rowCount + ' actors';
                                $scope.actors = response.data;
                                $scope.showSuccessMessage = true;
                                $scope.successMessage = "Actor Success";
                            },
                            function (err){
                                $scope.status = 'Unable to load data ' + err;
                            }
                        );  // end of getStudents().then
                    };

                // only if there has been a courseid passed in do we bother trying to get the students
                if ($routeParams && $routeParams.filmid) {
                    console.log($routeParams.filmid);
                    getActors($routeParams.filmid);
                }

                }
            ]
        )

这是MovieController中的selectFilm()代码

$scope.selectedFilm = {};
                    $scope.selectFilm = function ($event,movie) {
                        $scope.selectedFilm = movie;
                        $location.path('/actor/' + movie.film_id); 
                    }

这是电影控制器代码

).controller('MovieController', 
            [
                '$scope', 
                'dataService', 
                '$routeParams',
                '$location',

                function ($scope, dataService, $routeParams, $location){
                    $scope.movies = [ ];
                    $scope.movieCount = 0;

                    var getMovies = function (moviecode) {
                        dataService.getMovies(moviecode).then(
                            function (response) {
                                $scope.movieCount = response.rowCount + ' movies';
                                $scope.movies = response.data;
                                $scope.showSuccessMessage = true;
                                $scope.successMessage = "Movies Success";
                            },
                            function (err){
                                $scope.status = 'Unable to load data ' + err;
                            }
                        );  // end of getStudents().then
                    };
                    $scope.selectedFilm = {};
                    $scope.selectFilm = function ($event,movie) {
                        $scope.selectedFilm = movie;
                        $location.path('/actor/' + movie.film_id); 
                        // $window.location.href = '/actor/' + movie.film_id
                        console.log(movie.film_id);

                    }

                // only if there has been a courseid passed in do we bother trying to get the students
                if ($routeParams && $routeParams.categoryid) {
                    console.log($routeParams.categoryid);
                    getMovies($routeParams.categoryid);
                }

                }
            ]
        )

当函数中未定义$ location变量时,我自己解决了该问题,后来在movie对象上没有film_id,因此我必须重新调整SQL查询以使其起作用。 更改SQL查询后,我可以立即路由页面。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM