R
R
Rabinzon2016-03-13 15:13:23
JavaScript
Rabinzon, 2016-03-13 15:13:23

How to use $http in es6 class?

export default class ThingFactory {
  constructor($http) {
    this.$http = $http;
    this.data = {
      name: "Name",
      age:  17
    };
  }
  get() {
    this.$http({
      method: 'GET',
      url: '/1'
    }).then(function successCallback(response) {
      console.log(response)
    }, function errorCallback(response) {
      console.log(response)
    });
  }
  newThing() {
    console.log('Getting a new Thing...');
    return this.data;
  }
}

How to inject $http ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bromzh, 2016-03-15
@bromzh

Include ngAnnotate and

export default class ThingFactory {
  // @ngInject
  constructor($http) {
  }
}
// ИЛИ
export default class ThingFactory {
  constructor($http) {
    "ngInject";
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question