angular JS 添加图片 gallery/viewer 打破单页路由

angular JS adding image gallery/viewer breaking single page routing

我是 Angular 的新手,所以这可能是一个真正的 simple/stupid 问题,但在谷歌搜索并尝试了很多东西后我无法让它工作。

我认为这可能与图像查看器没有直接关系,而是在尝试向代码中添加附加功能时的一个普遍问题(如下所示:angular.module('app', ['angular-flexslider']);) 我尝试了其他一些事情并且遇到了同样的问题所以这可能是一个普遍的问题关于我在添加这个时如何设置我的代码这会破坏包括路由在内的所有内容(但路由是唯一真正的功能我目前有。

如果我有图像查看器的独立页面,它工作正常,但将它与其他代码结合会导致问题。

 var app = angular.module('app', ['angular-flexslider']);

如果我将 "app" 更改为 "app1" 它不会导致所有路由中断,因此不是添加的脚本标记本身导致了问题,而是与此有关的东西和我是如何设置代码的(我认为有些事情正在发生交叉)。

我页面的重要代码是: 指数:

<!DOCTYPE html>

<html ng-app="app">
<head>

    <base href="/" />
</head>
<body>

    <link rel="stylesheet" href="styles/styles.css">

    <div class="header">
        <div class="container">
            <img src="/images/DPLogo.jpg" />
            <h1>Downriver Panters</h1>
        </div>
    </div>
    <div class="nav-bar">
        <div class="container">
            <ul class="nav">
                <li><a href="home">Home</a></li>                
                <li><a href="history">History</a></li>
                <li><a href="coaches">Coaches</a></li>
                <li><a href="activities">Activities</a></li>
                <li><a href="calender">Calender</a></li>
                <li><a href="gallery">Gallery</a></li>
                <li><a href="fundraisers">Fundraisers</a></li>
                <li><a href="links">Links</a></li>
                <li><a href="contactus">Contact Us</a></li>
                <li><a href="styletesting">Test Styles</a></li>
            </ul>
        </div>
    </div>



    <div class="content">
        <div class="container">
            <div ng-view>ViewPage</div>
        </div>
    </div>




    <div class="footer">
        <div class="container">
            &copy; Copyright 2016
        </div>
    </div>


    <!-- this is code for the image viewer that is causing it to break (but also add the app.js file below)-->
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="//code.angularjs.org/1.3.0/angular.js"></script>
    <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.min.js"></script>
    <script src="//cdn.jsdelivr.net/flexslider/2.2.2/jquery.flexslider-min.js"></script>

    <script src="/testing/angular-flexslider.js"></script>
    <script src="/scripts/angular.min.js"></script>
    <script src="/scripts/angular-route.min.js"></script>

    <!--  end of code causing it to break -->


    <!-- my main control with the routing -->
    <script src="/controllers/mainCtrl.js"></script>

    <!-- have to put here??  so below mainCtrl???  cause not working if put on home page -->
    <script src="/controllers/homeCtrl.js"></script>
    <script src="/controllers/calenderCtrl.js"></script>
    <script src="/controllers/coachesCtrl.js"></script>
    <script src="/controllers/galleryCtrl.js"></script>

    <!-- other file for routing that is causing it to break-->
    <script src="/testing/app.js"></script>

</body>
</html>

mainCtrl.js(加上我的路由代码)

(function () {
    'use strict';

    var app = angular.module('app', ['ngRoute']);


    // configure our routes
    app.config(['$routeProvider','$locationProvider',
      function ($routeProvider, $locationProvider) {

        $routeProvider


            // catch all go home
            .when('/', {
                templateUrl: '/partials/home.html',
                controller: 'homeController'
            })

            // route for the home page
            .when('/home', {
                templateUrl: '/partials/home.html',
                controller: 'homeController'
            })

            // route for the about page
            .when('/about', {
                templateUrl: '/partials/about.html',
                controller: 'aboutController'
            })

            // route for the contact page
            .when('/history', {
                templateUrl: '/partials/hisotry.html',
                controller: 'hisotryController'
            })

            // route for the contact page
            .when('/coaches', {
                templateUrl: '/partials/coaches.html',
                controller: 'coachesController'
            })

            // route for the contact page
            .when('/activities', {
                templateUrl: '/partials/activities.html',
                controller: 'activitiesController'
            })

            // route for the contact page
            .when('/calender', {
                templateUrl: '/partials/calender.html',
                controller: 'calenderController'
            })

            // route for the contact page
            .when('/gallery', {
                templateUrl: '/partials/gallery.html',
                controller: 'galleryController'
            })


            // catch all go home
            .when('/fundraisers', {
                templateUrl: '/partials/fundraisers.html',
                controller: 'fundraisersController'
            })

            // catch all go home
            .when('/links', {
                templateUrl: '/partials/links.html',
                controller: 'linksController'
            })


             // route for the contact page
            .when('/contactus', {
                templateUrl: '/partials/contactus.html',
                controller: 'contactusController'
            })

             // catch all go home
            .when('/styletesting', {
                templateUrl: '/partials/styleTesting.html',
                controller: 'styletestController'
            })


            // happens when nothing specificed
            .otherwise({
                redirectTo: '/'
            })



            // not working/finding sites
            // if you don't wish to set base URL then use this
            $locationProvider.html5Mode({
                enabled: true,
                requireBase: true
            });        

        }]);

})();

app.js 的代码(图像查看器页面的控件:

var app = angular.module('app', ['angular-flexslider']);

app.controller('MainCtrl', function ($scope) {
    var ctrl = this;
    $scope.prod = { imagePaths: [] };
    $scope.prod.imagePaths = [
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_cheesecake_brownie.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_lemon.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_donut.jpg' },
        { custom: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg', thumbnail: 'http://flexslider.woothemes.com/images/kitchen_adventurer_caramel.jpg' }
    ];
});

最后是图片的部分viewer/gallery页面

<div id="container" ng-controller="MainCtrl">
    <div class="col-sm-12">
        <flex-slider slider-id="slider" flex-slide="image in prod.imagePaths track by $index" animation="fade" animation-loop="false" sync="#carousel" slideshow="false" control-nav="false" init-delay="100">
            <li>
                <img ng-src="{{image.custom}}">
            </li>
        </flex-slider>
    </div>
    <div class="col-sm-12">
        <flex-slider slider-id="carousel" flex-slide="image in prod.imagePaths track by $index" animation="slide" animation-loop="false" item-width="210" item-margin="5" as-nav-for="#slider" slideshow="false" control-nav="false">
            <li>
                <img ng-src="{{image.thumbnail}}">
            </li>
        </flex-slider>
    </div>

</div>

您必须在一次调用中注入所有模块,因此您可以使用:

var app = angular.module('app', ['ngRoute','angular-flexslider']);

按照您当前的操作方式,您的模块在添加第二个模块时会被销毁。