ich eine Schaltfläche unten, wenn auf geklickt zeigt ein kleines Popup wie AnmeldungAnruf jQuery-Funktion von AngularJS-Controller
<button id="element" type="button" onclick="ShowNotifications()" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Text inside popup">Notifications</button>
<script type="text/javascript">
function ShowNotifications() {
$('#element').popover('open');
}
</script>
Meine Absicht ist es, ohne klicken auf die Schaltfläche dieses Pop-up all paar Sekunden zu zeigen, aber von den AngularJS-Controller .
var showPop = function() {
//how can i call that jQuery function here ??
$timeout(showPop, 1000);
}
$timeout(showPop, 1000);
Versuchte mit der unten Lösung
app.directive("showNotifications", ["$interval", function ($interval) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
$interval(function() {
$(elem).popover("open");
alert('hi');
}, 1000);
}
};
}]);
gehörte auch die Skripte
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="js/app.js"></script>
<script src="js/postsService.js"></script>
<script src="js/directive.js"></script>
<script src="js/controllers.js"></script>
mit der Richtlinie wie diese
<button id="element" type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Friend request 1" **show-notifications**>Live Notifications</button>
Ich sehe einen Fehler "das Objekt hat keine Methode popover"
diese Art von Sachen verdient eine Richtlinie. Stellen Sie keine Logik in Ihren Controller. Es ist auch kein rekursiver Aufruf erforderlich, angular unterstützt jetzt $ interval. –