Since custom promise in Angular.js can be hard to handle sometimes and can fall into malfunction in the worse case, the promise provides another way to implement itself. It asks you to transform your response within a then
method and returns a transformed result to the calling method in an autonomous way. Considering the same code we used in the previous section:
this.getSerial = function(serial) { return $http.get('/api/tv/serials/sherlockHolmes'+ serial) .then( function (response) { return { title: response.data.title, cost: response.data.price }); }); };
The output we yield from the preceding method will be a chained, promised, and transformed. You can again reuse the output for another output, chain it to another promise, or simply display the result.
The controller can then be transformed into the following lines of...