2017-10-17 29 views
0

我正在使用我在Internet上發現的Select類,問題是如果我在選擇動手操作中使用angluar ng-repeat創建選項,將不可點擊,但如果我手動創建它,也使用動態值,它可以被點擊。Ng-Repeat在ng-included代碼中無法正常工作

這是代碼:

MainFile:

... 
    <div id="SiteList" ng-controller="SiteController as siteCtrl" ng-if="masterCtrl.isUserLogged()" ng-include="'Select2/index.html'" ng-init="siteCtrl.getSites()" > 
... 

這是選擇二/ index.html的 ...

<body> 
    <div class="drop"> 
    <div class="option active placeholder" data-value="placeholder"> 
    Seleziona un sito 
    </div> 
    <div class="option" ng-repeat="sito in siteCtrl.siti" data-value="{{sito.name}}">{{sito.name}}</div> 

</div> 
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> 

    <script src="Select2/js/index.js"></script> 

</body> 

...

然後選擇二/js/index.js

$(document).ready(function() { 
    $(".drop .option").click(function() { 
    var val = $(this).attr("data-value"), 
     $drop = $(".drop"), 
     prevActive = $(".drop .option.active").attr("data-value"), 
     options = $(".drop .option").length; 
    $drop.find(".option.active").addClass("mini-hack"); 
    $drop.toggleClass("visible"); 
    $drop.removeClass("withBG"); 
    $(this).css("top"); 
    $drop.toggleClass("opacity"); 
    $(".mini-hack").removeClass("mini-hack"); 
    if ($drop.hasClass("visible")) { 
     setTimeout(function() { 
     $drop.addClass("withBG"); 
     }, 400 + options*100); 
    } 
    triggerAnimation(); 
    if (val !== "placeholder" || prevActive === "placeholder") { 
     $(".drop .option").removeClass("active"); 
     $(this).addClass("active"); 
    }; 
    }); 

    function triggerAnimation() { 
    var finalWidth = $(".drop").hasClass("visible") ? 22 : 20; 
    $(".drop").css("width", "24em"); 
    setTimeout(function() { 
     $(".drop").css("width", finalWidth + "em"); 
    }, 400); 
    } 
}); 

任何人有任何想法如何解決這個問題?

+0

NG-包括不是一個iframe,腳本將不會加載和body元素是redonant從頂級的之一。如果你想從jQuery/Vanilla/whatever中製作可重用的組件,請檢查angularJS的'directives'文件。 – Walfrat

回答