Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9057287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:25:00+00:00 2026-06-16T14:25:00+00:00

I have a 3rd party library that loads to my page asynchronously and I

  • 0

I have a 3rd party library that loads to my page asynchronously and I would like to use it as a service.

How can I wrap the loading code inside an angular service? In general what would be the best practice?

At the moment my approach is something like so:

angular.module('myAPIServices', []).
factory('MyAPI', function () {
    return {
        \\ API is declared at the loaded script
        doStuff:function(){$window.API.doStuff()} 
    };
});

and then on the page outside of the Angular scope

(function () {
    var js = document.createElement('script');
    var loc = document.getElementsByTagName('script')[0];
    js.async = true;
    js.src = "myAPI.js";
    loc.parentNode.insertBefore(js, loc);
}());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:25:01+00:00Added an answer on June 16, 2026 at 2:25 pm

    A posibility is to wrap your library call in $q. This angular service returns a promise, which you can resolve when the library is fully loaded.

    Your doStuff function would be something like:

    doStuff: function() {
       var deferred = $q.defer();
    
       myAsyncCall().success(function(data) {
          deferred.resolve(data);
       });
       return deferred.promise;
    }
    

    In your controller you use the then() function to process the results.

    A second possibility is with a callback. Here is an example of both types.

    If your library is manipulating the DOM, it is better to wrap it in a directive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do we have any free 3rd party library that we can use in asp.net
I have a class that uses 3rd party FTP library http://ftps.codeplex.com/ and I would
I have a 3rd party library that I use in my webapp. I need
I have a Winform App that uses a 3rd Party Library of Controls, DevExpress.
I have to use class Matrix4x4 from some 3rd party library, and I need
I have a 3rd party library that's written in C. It exports all of
I have a getViewBitmap() method that creates a Bitmap with a 3rd party library
so I have some 3rd party native library that works only in 32 bit
New to cpp (Java guy). I have 3rd party library that has method sendMail(txt).
I have a 3rd party library that is doing something internally that causes it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.