JSFiddle - React, Tailwind, and code Playground
by vvakame
HTML
<div ng-app="first">
<div ng-controller="Ctrl">
{{test}}
<ul>
<li ng-repeat="tweet in tweets">
<hr>
{{tweet.from_user_name}} 「{{tweet.text}}」
</li>
</ul>
</div>
</div>
JavaScript
var module = angular.module("first", [], function ($httpProvider) {
// 登録した順(配列の先頭から)に処理されるみたい
$httpProvider.responseInterceptors.push('firstHttpInterceptor');
$httpProvider.responseInterceptors.push('secondHttpInterceptor');
});
module.factory("firstHttpInterceptor", function () {
return function (promise) {
return promise.then(
function () {
alert("first success");
return arguments[0];
},
function (response) {
alert("first failure");
return arguments[0];
});
};
});
module.factory("secondHttpInterceptor", function () {
return function (promise) {
return promise.then(
function () {
alert("second success");
return arguments[0];
},
function (response) {
alert("second failure");
return arguments[0];
});
};
});
function Ctrl($scope, $http) {
$scope.test = "Hello tweets";
$http({
method: "JSONP",
url: "http://search.twitter.com/search.json?q=vvakame&callback=JSON_CALLBACK"
}).success(function (data, status, headers, config) {
console.log("result", data);
$scope.tweets = data.results;
});
};