Over a million developers have joined DZone.

How to Write AngularJS Frontends for LoopBack Applications

DZone's Guide to

How to Write AngularJS Frontends for LoopBack Applications

Niklas Heidloff provides an example of how to write AngularJS front-end against the Loopback Node.js API framework.

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

With the Node.js API framework LoopBack you can easily provide REST APIs for your applications. In order to build web frontends, LoopBack provides an AngularJS JavaScript SDK. Below is a sample application which demonstrates how to use this SDK.

Download the sample application from GitHub.

In AngularJS applications, you typically build views that interact with services via controllers. The services access data from the server-side applications. Obviously, you can write your own services which invoke the REST APIs of your LoopBack applications directly. But, LoopBack makes this even simpler via the AngularJS SDK. With the SDK, client-side JavaScript libraries are generated for your REST APIs so that the controllers can simply invoke JavaScript APIs rather than REST APIs.

The sample application demonstrates how to build a web-based frontend for a simple Approval Request scenario. Approval requests have titles, descriptions, requesters, and approvers.


Here is the code snippet of the controller that returns all approval requests. The class ApprovalRequest is provided by the LoopBack SDK.

angular.module('angularApp').controller('RequestsController', ['$scope', 'ApprovalRequest', function($scope, ApprovalRequest) {
  $scope.requests = [];
  function getRequests() {
        .then(function(results) {
          $scope.requests = results;
        function(err) {
          $scope.requestsError = err.statusText;

Authentication is also very easy from Angular. Just invoke the Person.login function.

The file lb-services.js with the JavaScript APIs for your own business objects defined via LoopBack is generated either via command line or via Grunt. The approval request sample application uses the Grunt plugin to build the file automatically and to put it in the Angular application.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

javascript ,angular js ,loopback ,web design and web development ,node js

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}