I have encountered an issue while using a Select class that I found on the Internet. When I dynamically create options in the Select using Angular's ng-repeat, the options are not clickable. However, if I manually create the options with dynamic values, they can be clicked.
Here is the code snippet:
MainFile :
...
<div id="SiteList" ng-controller="SiteController as siteCtrl" ng-if="masterCtrl.isUserLogged()" ng-include="'Select2/index.html'" ng-init="siteCtrl.getSites()">
...
This is Select2/index.html ...
<body>
<div class="drop">
<div class="option active placeholder" data-value="placeholder">
Select a site
</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>
...
Then the Select2/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);
}
});
Does anyone have any suggestions on how to fix this issue?