AngularJS - pnotify

by mrajcok

HTML

<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="https://raw.github.com/sciactive/pnotify/master/jquery.pnotify.min.js"></script>
<link rel="stylesheet" href="https://raw.github.com/sciactive/pnotify/master/jquery.pnotify.default.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<body ng-controller="TestCtrl">
    <button class="btn" ng-click="notify()">Notify</button>

</body>

CSS

/*
Document   : jquery.pnotify.default.css
Created on : Nov 23, 2009, 3:14:10 PM
Author     : Hunter Perrin
Version    : 1.2.2
Link       : http://pinesframework.org/pnotify/
Description:
    Default styling for Pines Notify jQuery plugin.
*/
/* -- Notice */
.ui-pnotify {
top: 25px;
right: 25px;
position: absolute;
height: auto;
/* Ensures notices are above everything */
z-index: 9999;
}
/* Hides position: fixed from IE6 */
html > body .ui-pnotify {
position: fixed;
}
.ui-pnotify .ui-pnotify-shadow {
-webkit-box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5);
-moz-box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5);
box-shadow: 0px 2px 10px rgba(50, 50, 50, 0.5);
}
.ui-pnotify-container {
background-position: 0 0;
padding: .8em;
height: 100%;
margin: 0;
}
.ui-pnotify-sharp {
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
}
.ui-pnotify-closer, .ui-pnotify-sticker {
float: right;
margin-left: .2em;
}
.ui-pnotify-title {
display: block;
margin-bottom: .4em;
}
.ui-pnotify-text {
display: block;
}
.ui-pnotify-icon, .ui-pnotify-icon span {
display: block;
float: left;
margin-right: .2em;
}
/* -- History Pulldown */
.ui-pnotify-history-container {
position: absolute;
top: 0;
right: 18px;
width: 70px;
border-top: none;
padding: 0;
-webkit-border-top-left-radius: 0;
-moz-border-top-left-radius: 0;
border-top-left-radius: 0;
-webkit-border-top-right-radius: 0;
-moz-border-top-right-radius: 0;
border-top-right-radius: 0;
/* Ensures history container is above notices. */
z-index: 10000;
}
.ui-pnotify-history-container .ui-pnotify-history-header {
padding: 2px;
}
.ui-pnotify-history-container button {
cursor: pointer;
display: block;
width: 100%;
}
.ui-pnotify-history-container .ui-pnotify-history-pulldown {
display: block;
margin: 0 auto;
}
/* Alternate stack initial positioning. */
.ui-pnotify.stack-topleft, .ui-pnotify.stack-bottomleft {
left: 25px;
right: auto;
}
.ui-pnotify.stack-bottomright, .ui-pnotify.stack-bottomleft {
bottom: 25px;
top: auto;
}

JavaScript

/* App Module */
var app = angular.module('builder', []);

/*Notify Service*/
app.service('notifyService', function($compile) {
    this.error = function(scope) {
        scope.errors = {
            "errors": [{
                "text": "error1"},
            {
                "text": "error2"}]
        };
        var htmlTemplate = '<p ng-repeat = "error in errors.errors">{{error.text}}</p>';
        $.pnotify({
            title: 'title',
            text: htmlTemplate,
            type: 'error',
            addclass: 'myClazz'
        });
        // now that htmlTemplate has been added to the DOM, $compile it
        var element = $('.myClazz');
        $compile(element)(scope);
    };
});

//Controller
app.controller('TestCtrl', function TestCtrl($scope, notifyService) {
    $scope.notify = function() {
        notifyService.error($scope);
    }
});