Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 重新初始化控制器上的指令_Html_Angularjs - Fatal编程技术网

Html 重新初始化控制器上的指令

Html 重新初始化控制器上的指令,html,angularjs,Html,Angularjs,我有一个旋转木马,它从一个数组中加载一组项目,但是使用了一个指令来显示旋转木马 如果选择了某个项目,我想从列表(如“street parties”)中删除该项目,但由于该项目列表似乎绑定到一个指令,如何重新加载该指令?我也见过类似的问题,但我似乎还没找到解决办法。。多谢各位 在我的控制器中,我有这样的各种项目 this.eventProducts.push({ link: "/quote/bar-and-bat-mitzvah-insurance",

我有一个旋转木马,它从一个数组中加载一组项目,但是使用了一个指令来显示旋转木马

如果选择了某个项目,我想从列表(如“street parties”)中删除该项目,但由于该项目列表似乎绑定到一个指令,如何重新加载该指令?我也见过类似的问题,但我似乎还没找到解决办法。。多谢各位

在我的控制器中,我有这样的各种项目

this.eventProducts.push({
                link: "/quote/bar-and-bat-mitzvah-insurance",
                image: "/Content/Images/policies/bar-mitzvah.jpg",
                name: "Bar and Bat Mitzvahs"
            });
            this.eventProducts.push({
                link: "/quote/street-party-insurance",
                image: "/Content/Images/policies/street-party.jpg",
                name: "Street Parties"
            });
            this.eventProducts.push({
                link: "/quote/conference-and-meetings-insurance",
                image: "/Content/Images/policies/conference.jpg",
                name: "Conferences and Meetings"
            });
<div class="row homepage-events">
    <div class="homepage-heading"><h2 class="text-center">A Selection of our Most Popular Event Insurance Policies</h2></div>
    <data-owl-carousel class="owl-carousel" data-options="{navigation: false, pagination: true, rewindNav : true}">
        <div class="carousel-item" owl-carousel-item="" data-ng-repeat="product in ::homepageController.eventProducts">
            <div class="">
                <div class="thumbnails thumbnail-style thumbnail-kenburn">
                    <div class="thumbnail-img">
                        <div class="overflow-hidden">
                            <a class="" href="{{::product.link}}">
                                <img data-ng-src="{{::product.image}}" alt="{{::product.altText}}" />
                            </a>
                        </div>
                        <a class="btn-more2 hover-effect">Insurance for</a>
                        <a class="btn-more hover-effect" data-ng-href="{{::product.link}}">{{::product.name}}</a>
                    </div>
                </div>
            </div>
        </div>
    </data-owl-carousel>
</div>
然后我有一个指令,它设置旋转木马

angular.module("App")
        .controller("HomepageController", HomepageController)
        .config(["$routeProvider", HomepageController.routing])
        .directive("owlCarousel", () => {
            return {
                restrict: "E",
                transclude: false,
                link: (scope:any) => {
                    scope.initCarousel = (element) => {
                        // provide any default options you want
                        var defaultOptions = {
                        };
                        var customOptions = scope.$eval($(element).attr("data-options"));
                        // combine the two options objects
                        for (var key in customOptions) {
                            defaultOptions[key] = customOptions[key];
                        }
                        // init carousel
                        (<any>$(element)).owlCarousel(defaultOptions);
                    };
                }
            };
        })
        .directive("owlCarouselItem", [() => {
            return {
                restrict: "A",
                transclude: false,
                link:  (scope, element) => {
                    // wait for the last item in the ng-repeat then call init
                    if (scope.$last) {
                        scope.initCarousel(element.parent());
                    }
                }
            };
        }]);
角度模块(“应用程序”) .controller(“HomepageController”,HomepageController) .config([“$routeProvider”,HomepageController.routing]) .指令(“owlCarousel”,()=>{ 返回{ 限制:“E”, 排除:错误, 链接:(范围:任意)=>{ scope.initCarousel=(元素)=>{ //提供您想要的任何默认选项 var defaultOptions={ }; var customOptions=scope.$eval($(元素).attr(“数据选项”); //将两个选项组合到对象中 for(自定义选项中的var键){ defaultOptions[key]=自定义选项[key]; } //初始旋转木马 (
一旦您从列表中删除项目,
摘要周期应被触发,
ng repeat
将删除该项目。感谢您的回复。它似乎无法识别何时添加或删除项目。我尝试了此操作。scope.$apply();强制执行此操作,但出现错误“apply ready in progress”。你如何创建你的代码的实时演示,JSFIDLE或其他东西。这是一个大项目的一部分。因此,在JSFIDLE中包含所有内容需要一些时间。当它第一次加载时,你会看到旋转木马中的所有十项(我显示了3项,但有10项),必须有一种简单的方法来重新触发作用域上的初始化。该指令已创建了一个孤岛化的作用域,因此重新初始化是否很棘手?通过在绑定中使用
,您正在终止双向绑定,为什么要这样做,请尝试至少在ng repeat中删除它。