A service that posts in Angular

Angular interview exercise on HttpClient, difficulty 2 of 3. Solve it in the editor beside a worked example; the tests run the moment you do.

TodoApi.create(title) POSTs { title } to /api/todos and resolves with the created todo ({ id, title }). NewTodoComponent has an <input> and a <button class="save">: clicking calls the service, and once the answer arrives the todo appears in <ul> as <li>#id title</li> and the input is cleared.

Each exercise pairs a worked example with a twin problem to solve in a real editor; the tests run the moment you do. Progress is saved in your browser, and in your account if you sign in.

More HttpClient in Angular

All Angular exercises · Other languages and frameworks