Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<button ng-click="test()">test</button>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope, $http) {
function test1() {
return $http.get("google.com").then(function (data) {
console.log("OK1");
}, function (data) {
console.log("ERROR1");
});
}
$scope.test = function() {
test1().then(function (data) {
console.log("OK2");
}, function (data) {
console.log("ERROR2");
});
}
}