83464

How to use AngularJS to build javascript widgets for public use?

I'm trying to build a JavaScript widget that will allow webmasters to just cut and paste a few lines of code to display some functionality and UI on their site.

I've seen a good example of doing this kind of thing in JQuery, but not Angular. I'm assuming the widget will need to download the angularjs javascript file conditionally (based on whether it has already been loaded).

Has anyone had experience doing this in Angular and can recommend whether or not to do it in Angular or just stick with jQuery?

e.g. FourSquare's widget code: Save to foursquare

<script type='text/javascript'> (function() { window.___fourSq = {"uid":"606"}; var s = document.createElement('script'); s.type = 'text/javascript'; s.src = 'http://platform.foursquare.com/js/widgets.js'; s.async = true; var ph = document.getElementsByTagName('script')[0]; ph.parentNode.insertBefore(s, ph); })(); </script>

Answer1:

I believe AngularJS is a framework with is targetted towards Single Page Apps (SPA) and provides all the infrastructure around it. The use of widget within existing HTML pages is not a ideal use case for using AngularJS.

jQuery is more of a utility belt \ library and hence can be used anywhere.

Recommend

  • MVC3 - Conditionally add id element with Razor
  • When should I use mb_strpos(); over strpos();?
  • Fixed position layer (div) in relation to its parent div (with overflow:auto)
  • AngularJS sorting a list with nulls
  • SSL Certificate Context - How to get it using NPAPI
  • Trigger once after event created using fullcalendar.io
  • How can I migrate my WP8 application to universal when it uses a local linq to sql db?
  • Drupal: Hierarchical taxonomical breadcrumb trail
  • Maintaining XML comments during XSL Transformations
  • angular Scroll div on button click
  • Can I put condition in emacs lisp macro?
  • Getting webGL error in autodesk viewer
  • Application Express: Anonymous PL/SQL Block and Bind Variables
  • How to re-render views using Angular JS
  • When querying against a view, a filtering clause in the view's definition is being ignored
  • How to best manage SMTP clients
  • Detect language of Word document
  • Swift iOS don't recognize GCM library imports?
  • Distributed JMS based logging .. falling flat?
  • Sensibility of combined Maven/Ant+Ivy build management for dual platform Desktop/Android deployment?
  • Declaring variable dynamically in VB.net
  • Use of this Javascript
  • C++ Partial template specialization - design simplification
  • Ajax Loaded meta Tags
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • HTML download movie download link
  • Updating server-side rendering client-side
  • How to get next/previous record number?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • File upload with ng-file-upload throwing error
  • Python: how to group similar lists together in a list of lists?
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Free memory of cv::Mat loaded using FileStorage API
  • How to set the response of a form post action to a iframe source?
  • coudnt use logback because of log4j
  • Java static initializers and reflection
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Why do underscore prefixed variables exist?