【问题标题】:Controller 'carousel', required by directive 'ngTransclude', can't be found找不到指令“ngTransclude”所需的控制器“轮播”
【发布时间】:2013-11-22 05:49:32
【问题描述】:

我们的团队为我们的首页实施了一个 twitter 引导轮播。 Chrome 和 Firefox 一切正常。但是当我们在 IE 8 中测试它时,轮播图像被破坏并且在 IE 控制台中抛出的错误是

Controller 'carousel', required by directive 'ngTransclude', can't be found

这是我们轮播的代码(以haml格式):

%carousel.featuredTags{'ff-destroy-carousel' => 'true', 'interval' => "5000"}
%slide
  %img{:src => "#{$assetsPath}/img/pic-bora.png", :alt => ""}
    .dimmer
    .caption Boracay beach, Aklan
%slide
  %img{:src => "#{$assetsPath}/img/pic-bora.png", :alt => ""}
    .dimmer
    .caption Boracay beach, Aklan
%slide
  %img{:src => "#{$assetsPath}/img/pic-bora.png", :alt => ""}
    .dimmer
    .caption Boracay beach, Aklan
%slide
  %img{:src => "#{$assetsPath}/img/pic-bora.png", :alt => ""}
    .dimmer
    .caption Boracay beach, Aklan

如果浏览器是 IE 8,我们的第一个方法是销毁轮播(因此,ff-destory-carousel 指令)并使用 bowser.js 进行浏览器检查。但是还是会弹出脚本错误。

对于为什么在 IE 8 中仍然会发生这种错误以及是否有可能解决此问题的任何想法?

【问题讨论】:

    标签: javascript html twitter-bootstrap


    【解决方案1】:

    无需禁用 ui.bootstrap 即可轻松修复,只需在您自己的 .js 文件中重新初始化 carousel 指令:

    angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
        .controller('CarouselController', ['$scope', '$timeout', '$transition', '$q', function        ($scope, $timeout, $transition, $q) {
    }]).directive('carousel', [function() {
        return {
    
        }
    }]);
    

    您可以在my blog(俄语)中了解此内容。

    【讨论】:

    • 有没有人设法实现这个,或者有解决这个问题的新更新? p.s.我不会说俄语
    【解决方案2】:

    我在最后一个 angular-ui-bootstrap 3 分支上遇到了同样的问题。 当您使用 class="carousel"slide="" 时,将调用 Carousel 指令。

    它看起来像 angularjs 1.2 中的一个错误,因为它只能在 Element 或 Attribute 上编译。我不够专业,无法研究 $scompile

    .directive('carousel', [function() {
      return {
        restrict: 'EA',
        transclude: true,
        replace: true,
        controller: 'CarouselController',
        require: 'carousel',
        templateUrl: 'template/carousel/carousel.html',
        scope: {
          interval: '=',
          noTransition: '=',
          noPause: '='
        }
      };
    }])
    
    .directive('slide', ['$parse', function($parse) {
      return {
        require: '^carousel',
        restrict: 'EA',
        transclude: true,
        replace: true,
        templateUrl: 'template/carousel/slide.html'
    

    从依赖项中删除 ui.bootstrap.carousel “解决”问题 (尽管这不应该是这里的问题)

    【讨论】:

      猜你喜欢
      • 2014-08-25
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      相关资源
      最近更新 更多