I have a simple directive that displays three images. On mouse hover, it should switch from black and white to normal image. Below given is the code inside the directive.
<div class="container">
<div class="row">
<div class="col-md-4">
<h3>
Example 1</h3>
<div class="fd-fade1 fd-effect">
<img src="http://i.imgur.com/yxAxCaK.jpg" class="fd-img1" alt="">
</div>
<!-- /.fd-fade -->
</div>
<!-- /.col-md-4 -->
<div class="col-md-4">
<h3>
Example 2</h3>
<div class="fd-fade2 fd-effect">
<img src="http://i.imgur.com/jlattvQ.jpg" class="fd-img2" alt="">
</div>
<!-- /. fd-fade -->
</div>
<!-- /.col-md-4 -->
<div class="col-md-4">
<h3>
Example 3</h3>
<div class="fd-fade3 fd-effect">
<img src="http://i.imgur.com/XqtS5WA.jpg" class="fd-img3" alt="">
</div>
<!-- /. fd-fade -->
</div>
<!-- /.col-md-4 -->
</div>
<script type="text/javascript">
$(document).ready(function () {
debugger;
$('.fd-effect').hover(function () {
$(this).children("img").stop().fadeIn('slow');
// add .stop() to prevent event chaining
}, function () {
$(this).children("img").stop().fadeOut("slow");
}); // end .fd-effect
}); // end document.ready function
</script>
</div>
The jQuery script for the hover is shown above (embedded inside the template).
My problem!!!
This code does not run inside an angularjs directive.Event the debugger does not get hit. Could someone please help me understand why it does not run?
P.S The code does run if not inside a directive.
--edit..
Since the question is way too vague for many, let me clarify.
I have a simple angular directive , that uses a template . This template contains html and inline javascript to render out 3 images .
The directive :
var app = angular.module('albumApp', []);
app.directive('album', function ($log) {
return {
restrict: 'E',
templateUrl: 'templates/default.htm',
replace: true
};
}
This is all that I have .The html is the one present in the default.htm
In the main html page,
I just write and I expect the html to be rendered and jQuery to perform like normal.
<html ng-app="albumApp">
<head>
<title>Test</title>
<head>
<body>
<album />
</body>
</html>
Do note: The the directive works and the template gets rendered. But the script inside the template is not functioning. My doubt is why!