0

I am experienced in ASP.NET and web/database applications; I am learning and trying out Angular. I found a very good database example at w3schools.com, here:

http://www.w3schools.com/angular/angular_sql.asp

(see sections "Fetching Data From an ASP.NET Server Running SQL" and "4. Server Code ASP.NET, VB Razor and SQL Lite").

The Angular code is just:

$http.get("http://www.w3schools.com/angular/customers_sql.aspx")

and the sample query in the aspx page is:

"SELECT CompanyName, City, Country FROM Customers"

My problem is, there is no explanation of how to pass parameters to a query similar to this:

"SELECT CompanyName, City, Country FROM Customers Where Country = " & txtSomething

I know how to change the aspx page to read parameters on the ASP.NET side, but I don't know how to pass them from the Angular code.

How should I modify this Angular code to pass parameters to the aspx page?

var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("http://www.w3schools.com/angular/customers_sql.aspx")
    .success(function (response) {$scope.names = response.records;});
});

Thank you.

cips
  • 3
  • 1
  • 2

2 Answers2

1

You can add a query string to the request.

angular.http provides an option for it params.

$http({ url: "http://www.w3schools.com/angular/customers_sql.aspx", method: "GET", params: {id: someId} });

samee
  • 156
  • 7
0

Your easiest option is probably to add query string parameters:

"htp://www.w3schools.com/angular/customers_sql.aspx?country=" + $scope.country
Crowcoder
  • 11,250
  • 3
  • 36
  • 45