引导轮播不适用于角度 ng 路由

Bootstrap Carousel not working with angular ng-route

本文关键字:ng 路由 适用于 不适用      更新时间:2023-09-26

我正在使用ng-route创建一个简单的angularjs应用程序,索引.html页面有一个引导轮播,单击该按钮时具有下一个和上一个按钮正在导航到下一个Html页面 下面是我的 plunkr 链接以及我的脚本.js文件 如果我错了,请进行更正,我已经搜索了很多,但没有找到适合此问题的解决方案

工作链接

var appname = angular.module('appname', ['ngRoute', 'ngAnimate']);
appname.config(['$routeProvider',
  function ($routeProvider) {
      $routeProvider.
        when('/', {
            templateUrl: 'indexView.html',
            controller: 'indexController'
        }).
        when('/about', {
            templateUrl: 'about.html', 
        }).
        when('/contact', {
            templateUrl: 'contact.html', 
        }).
        otherwise({
            redirectTo: '/'
        });
  }]).controller('MainCtrl', function($scope, $location) {
    $scope.isIndexPage = function() {
      return $location.path() === '/';
    }
  });

检查一下,现在一切正常。

http://plnkr.co/edit/JcInw9ZUz6vfFO5InV7N?p=preview

重写了MainCtrl部分,在创建一次MainCtrl并且从未更新之前,但现在它会侦听路线更改并相应地隐藏轮播。

$scope.$on('$routeChangeSuccess', function () {
  $scope.isIndexPage = $location.path() === '/';
});