javascript - paramaterising $http response handling function in AngularJS -
i trying pass query string function paramater along "$http" data returned using angular (see code below).
i'm sure it's basic i've spent 2 days on looking through stack overflow, proangularjs book, w3c online javascript , angular documentation, code academy angularjs... , , stuck.
if remove 'select' function call , querystring paramater function definition works fine need pass query string paramater function ...
code below...
<html> <head> <title>hhldsummaryproj </title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular- route.min.js"></script> <script> var summaryapp = angular.module("summaryapp", ['ngroute']); summaryapp.config(['$routeprovider', function($routeprovider) { $routeprovider. when('/viewcounts', { templateurl: 'count.htm', controller: 'topsummaryctrl' }). otherwise({ redirectto: '/viewcounts' }); }]); /* inject $scope object , data retrieval factories */ summaryapp.controller('topsummaryctrl', function($scope, itemsummary){ itemsummary.success(function(response, "select") { $scope.itemsummaryresults = response.results.bindings; }); }); summaryapp.factory('itemsummary', function($http, querystring){ /* 1 count of data triples */ var query = encodeuricomponent(querystring+' (count(*) ?no) { ?s ?p ?o }'); var endpoint = "http://localhost:3030/dataset/query"; return $http.get("http://localhost:3030/dataset/query?query="+query+"&output=json&stylesheet=") }); </script> </head> <body> <h2>your data looks ... </h2> <div ng-app="summaryapp"> <div ng-view></div> <script type="text/ng-template" id="count.htm"> <table> <tr ng-repeat="x in itemsummaryresults"> <td>count of data "records" or "triples": {{ x.no.value }} </a></td> </tr> </table> </script> <!-- end viewcounts --> </div> </body> </html>
really basic example how pass data factory:
var summaryapp = angular.module("summaryapp", []) .controller('topsummaryctrl', ['$scope', 'itemsummary', function($scope, itemsummary) { itemsummary.getitems("12345").success(function(response) { //"12345" value passed factory console.log(response); }).error(function(response){ console.log(response); }); }]).factory('itemsummary', ['$http', function($http) { return { getitems: function(querystring) { //querystring equals "12345" return $http.get("http://echo.jsontest.com/uid/" + querystring + "/value/nuno_bettencourt"); }, pushitems: function(object) { //do want etc etc "itemsummary.pushitems()" } }; }]);
is required?
in example passing "querystring" variable dependency service, factory, provider...
another thing... sure want pass complete sql query url param? drop table, truncate table...
Comments
Post a Comment