Use angularjs withe other libraries js in the same application ??

317 views
Skip to first unread message

biloki

unread,
Mar 27, 2014, 6:11:28 AM3/27/14
to ang...@googlegroups.com
Hello everyone,

I'm passionated by Angularjs. 
But sometime I have to integrate the other libraries with angularjs. For example: the javascript canvas library fabricjs, svg library raphaeljs, d3js ..... 
Normally there are the methods, properties of these liraries. If I don't use Angularjs, I call these methods or properties directly. 
But in the application that use Angularjs, I want to have clean application structure . So what is the good way to integrate with the application that uses angularjs ?
For example: I use fabricjs in app, there is the method in fabrics that can add a rectangle to canvas: canvas.add(rectangle); .... 
Should I write a function in a controller for ex addRectangle, and this function calls the function of fabricjs or I should create the directive for that ?

If you already use angularjs with the other library in the same application, pls advice me your some experiences, thank you very much

Luke Kende

unread,
Mar 28, 2014, 2:29:02 AM3/28/14
to ang...@googlegroups.com
Yes.  I have used several other libraries with AngularJs.  Mostly I try to use angular only whenever possible, but when I use other libraries, it's typically in services/factories.  Technically they should probably converted to angular directives, but who has time to rewrite a complex library.

For example, I use a growl/notifications from pnotify.  I have a service called notify and it defines methods that I can call from controllers or directives to fire notifications.  This is an oversimplified version to give you the idea:

angular.module('app', [])
  .service('notify', function(){

       //set any initialization or defaults.
       jQuery.pnotify.defaults  = { ... my defauls ... }
      
      //return service as object methods to call
      return {
         growl: function(type, message){
           jQuery.pnotify({ type: type, message: message, sticky: true, delay: 800 })
         }
     }
    
  });

biloki

unread,
Mar 28, 2014, 8:41:21 AM3/28/14
to ang...@googlegroups.com
Yep, that's a good idea. Thank you
Reply all
Reply to author
Forward
0 new messages