thanx for AngularJS at all, but i'm still fresh in the brilliant world;
so my need:
- embded Angular into existent site(built by bottle)
- work with RESTful api, such as:
$ curl
http://localhost:8080/api/ct/x13061418375031396CRX90/dl
{"msg": "increased", "uuid": "x13061418375031396CRX90", "echo": 7,
"method": "GET", "act": "ct/dl"}
- means summation download number,total number back echo as "echo":7
in my try demo, had finished this function:
<!doctype html>
<html lang="zh" ng-app>
<head>
</head>
<body>
<div ng-controller="restService">
<h1><a href="#"
ng-click="rest_up_dl('x13061418375031396CRX90')">download</a></h1>
<h1>total: [[theme_dl]]!</h1>
</div>
<script src="
https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="
https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.min.js"></script>
<script>
function restService($scope, $http) {
$scope.method = 'GET';
var apiurl = '
http://localhost:8080/api/ct/dl/'
$scope.rest_up_dl = function(uuid) {
$scope.response = null;
var uri = apiurl+uuid
$http({method: 'GET', url: uri}).
success(function(data, status) {
console.log("data:"+data);
console.log("success:"+data.echo);
$scope.status = status;
if(0==data.success){
$scope.dc = "error by srv.";
}else{
$scope.theme_dl = data.echo;
$scope.isAllFetched = true;
}
}).
error(function(data, status) {
console.log("error:"+status);
}
);
};
};
angular.bootstrap(document.documentElement,
[function($interpolateProvider){
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
}]);
</script>
</body></html>
BUT:
- as snap showed
- every time, i click the "download" link
- console log showed that $http function is run twice?!
what is happened?
where is my mistake?
AND i know $resource is recommend replace $http
- but all i fund demo is not show how to sent into page parameter , like
ng-click="rest_up_dl('x13061418375031396CRX90')"
- because the html page is generated by Python
- for the existent site, i'm no time rebuild all by Angular
thanx for all suggest...
--
人生苦短, Pythonic! 冗余不做,日子甭过!备份不做,十恶不赦!
KM keep growing environment culture which promoting organization be learning!
俺:
http://about.me/zoom.quiet
许:
http://creativecommons.org/licenses/by-sa/2.5/cn/