angular Promise

by Prasad

JavaScript

export default {
  template: require('./wp-entry.jade'),
  controller: "WPEntryController",
  controllerAs: "ctrl"
};

class WPEntryController {
    static $inject = ["$location", "WPEntryService"];
    constructor($location, WPEntryService, $http) {
        console.log("IN WPEntryController");
        this.$location = $location;
        this.WPEntryService = WPEntryService;
        this.loadWPEntryPagewithData();
        this.WPDataObject;
    }
    loadWPEntryPagewithData(){
        this.WPEntryService.loadWPEntryData().then(function(promise){

        });
    }
    storeObject(Objects){
        console.log("object: "+objects.title);
    }
    choosePath(path) {
         this.$location.path(path);
    }
}
angular.module("app").controller("WPEntryController", WPEntryController);
---------------------------------------------------------------
class WPEntryService {
  static $inject = ["$http"];
  constructor($http) {
    this.$http = $http;
  }
    loadWPEntryData() {
        //read json file or provide URL for data
        var promise = this.$http.get('public/WPEntry_page.json')
            .then(function (dataObject) {
                return dataObject.data;
            })
            .catch(function (response) {
                return response;
            });
        return promise;
    }
}

angular.module('app').service('WPEntryService',WPEntryService);