SHARE
TWEET

Untitled

a guest Jan 24th, 2016 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var app = angular.module('myApp', []);
  2.  
  3.  
  4. app.service('getDataFile', ['$http', function($http) {
  5.     var service = this;
  6.     service.getStream = function (pid) {
  7.         return $http.get("data/" + pid + ".json")
  8.             .then(function(data) {
  9.                     console.info("Found data for pid " + pid);
  10.                     return data;
  11.             })
  12.             .catch(function(err) {
  13.                     console.error("Cant find data for pid " + pid);
  14.                     return err;
  15.             });
  16.     };
  17. }]);
  18.  
  19.  
  20. app.controller('MainController', ['getDataFile',
  21.     function(getDataFile) {
  22.         var ctrl = this;
  23.  
  24.         getDataFile.getStream('10101011').then(function(data) {
  25.             ctrl.myVar = data.someField;  // etc etc etc
  26.         });
  27.  
  28.     }]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top