2016-07-31 15 views
0

unter Code-Snippet platziert wird, funktioniert gut, wenn unter Vorlage URL-Seite platziert. Wenn wir es jedoch in separate js-Datei oder controler-Datei einfügen, funktioniert es nicht. Wie kann ich jquery in einer Controller-Datei hinzufügen?JQuery funktioniert nicht angularjs Controller-Datei. Funktioniert, wenn Code-Snippet intern

<script> 

$(document).ready(function() { 
    $("#notificationLink").click(function() { 
     $("#notificationContainer").fadeToggle(300); 
     $("#notification_count").fadeOut("slow"); 
     $('#notificationLink > i.fa-bell').addClass('fa-bell-o'); 
     $('#notificationLink > i.fa-bell').removeClass('fa-bell'); 
     return false; 
    }); 

    //Document Click hiding the popup 
    $(document).click(function() { 
     $("#notificationContainer").hide(); 
    }); 

    //Popup on click 
    $("#notificationContainer").click(function() { 
     return false; 
    }); 

    /* $('#AddNew').on('click', function() { 
     $('#notificationsBody ul').append('<li>New Message</li>'); 
    }); 
*/ 
}); 
</srcipt> 
+1

Warum verwenden Sie nicht nur eckig dafür? – developer033

Antwort

0

Der richtige Ort für die Verwendung von jQuery in einer Angular App ist in einer Direktive mit jqlite. Sie können es auch in die gleiche Datei des Controllers stecken, solange es danach ist.

+0

Ja ... Ich habe das gelesen !! .. und jquery funktioniert, wenn es in die benutzerdefinierte Anweisung eingefügt wird. – user2412105

+0

.directive ('NOTIFY', function() {return { -umfang: {}, beschränken: 'E', /* Vorlage: 'Ich bin x', */ Link: Funktion (scope, Element, attrs) { $ (Dokument) .ready (Funktion() { $ ('# notificationLink'). click (function() { $ ('# notificationContainer'). fadeToggle (300); $ ('# notification_count ') .fadeOut (' langsam '); $ (' # notificationLink> i.fa-bell '). addClass (' fa-bell-o '); $ (' # notificationLink> i.fa-bell ') .removeClass ('fa-bell'); return false; }); – user2412105