Hi,
I have a block of code (bootstrap dropdown) which I want to convert into a directive:
<div class="btn-group btn-block">
<button type="button" class="btn btn-default dropdown-toggle btn-block" data-toggle="dropdown">
<span class="selection">Choose Language</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu languagedropdown" role="menu">
<li ng-repeat="language in languages"><a href="#">{{language.LangName}}</a></li>
</ul>
</div>
I want
it to be shown like this:
<languageSelect></languageSelect>
<selectDropdown data=language></selectDropdown>
First of all, since the dropdown is not a tipical select / option dropdown, I use the following jQuery to derive the selected value:
$(".languagedropdown li a").click(function(){
angular.element($('body')).scope().filterLanguage($(this).text());
angular.element($('body')).scope().$apply();
$('.m-item').removeClass('m-active');
$('.m-scooch').scooch('reset');
var text = $(this).text() == "All" ? "Choose Language" : $(this).text();
$(this).parents(".btn-group").find('.selection').text(text);
}); Second, I call the filterLanguage() function in my directive since I want to change the “all” value to filter = “”.
Code in my Controller:
$scope.filterLanguage = function(filterValue) {
$scope.selectedLanguageFunction = (filterValue == "All") ? "" : filterValue;
}
The
issue I am having is as follows:
Once I convert to html codeblock to a controller, my jQuery (second code block) is not working anymore, since the jQuery cannot find the DOM elements anymore.
What I guess is that the jQuery needs to be:
But all my attempt are failing.
Is there anybody who can help me out with a good code example of the directive? (eg. How to fix the jQuery thing?)
Dutch indeed ;-) But let's stick to English for the sake of Information Sharing ;-)
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/uMiDC8FD8rA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Hi Jan Willem
Well, you first have to loose the jQuery habit before you will be able to make well-function directives ;)
This one is not that hard, and mostly an template directive, so you might give it a go.
You don’t need the $('.m-item').removeClass('m-active'); at all, you have ng-class="{'m-active':$first}" in your template, and that takes care of that.
I have no clue what the $('.m-scooch').scooch('reset') does, so I can’t tell you anything about that. If you want me to help you, you have to educate me a bit
about it.
Regards
Sander
first of all, I need to instanciate scooch to get a working (scrollable) carousel. I do this by the following code: $('.m-scooch').scooch() inside the document.ready()I think the instanciation does not need to be implemented in de directive of the dropdown though.
Secondly, I use $('.m-item').removeClass('m-active') because of the following:To demonstrate: Please load the fiddle, and go to the third thumbnail (second outlander thumbnail).Now change the dropdown to "english". You see that the m-active class stays active on the second outlander movie.
Thirdly, I made a jQuery prototype extension in de scooch.js, that will allow the carousel to reset, to if I change the filter, the carousel needs to be reset to its beginning position.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/uMiDC8FD8rA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
IFE.directive('carousel', function() { return { restrict: 'A', link: function(scope, element, attr){ scope.$watch('selectedLanguageFunction', function(){ //alert('veranderd!'); element.scooch('reset'); }) } };}); $(".languagedropdown li a").click(function(){
//$('.m-scooch').scooch('reset');
});Nice!! really looking forward to it!
2014-09-26 15:48 GMT+02:00 Sander Elias <sande...@gmail.com>:
Hi Jan Willem,Yes, you are right, it will start at 18:00. Food is included. We will have a introduction and a workshop withangular 2.0. We have talked the stuff trough, and it will be very informative/awesome ;)Besides the official agenda, there will be room for networking and socializing.RegardsSander
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/uMiDC8FD8rA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+unsubscribe@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Hi Jan Willem,
I see you are on the right path. You are building directives that are directly solving your current issues. That is great.
But I’ll give you this thought:
scope.$watch('selectedLanguageFunction', function(){
element.scooch('reset');
})
What will happen if you want to reuse your carousel in a setting where there is a different trigger then selectedLanguageFunction?
Regards
Sander