Whenever I attempt to invoke the getTodos function in the controller, it seems to be returning no value. I am trying to store the value returned by the getTodos() function into this.todos
. However, this.todos
keeps returning null.
/* ----- todo/todo.service.js ----- */
class TodosController {
constructor(TodoService) {
'ngInject'
this.ArtistsListService = ArtistsListService;
}
$onInit() {
this.todos = null;
this.TodoServiceService.getTodos().then(response =>
this.todos = response);
console.log(this.todos);
}
}
export default TodosController;`
/* ----- todo/todo.service.js ----- */
export class TodoService {
constructor($http) {
'ngInject';
this.$http = $http;
}
getTodos() {
return this.$http.get('/api/todos').then(response =>
response.data);
}
}
/* ----- todo/todo.module.js ----- */
import angular from 'angular';
import { TodoComponent } from './todo.component';
import { TodoService } from './todo.service';
import './todo.scss';
export const TodoModule = angular
.module('todo', [])
.component('todo', TodoComponent)
.service('TodoService', TodoService)
.name;