d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

How to Write AngularJS Frontends for LoopBack Applications

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() {
      approvalrequest.find().$promise
        .then(function(results) {
          $scope.requests = results;
        }, 
        function(err) {
          $scope.requestserror = err.statustext;
        }
    );
  }
  getrequests();
}]);

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.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this