Overview
In this article, we will see how to pass and retrieve parameters from URL in AngularJS. We will be using the same example which we had used in AngularJS routing i.e our Demo Application. In that, we are displaying the list of students with the help of web service and students controller in the URL and after displaying the data from AngularJS Controller, we will add a hyperlink to each of the student record and display various details.

For more articles on AngularJS, refer to
- Overview Of AngularJS
- Modules And Controller In AngularJS
- Controllers in AngularJS
- AngularJS ng src Directive
- AngularJS ng-Repeat Directive
- Handling Events In AngularJS
- How To Use Two-Way Data Binding In AngularJS
- Filters In AngularJS
- Sorting Data In AngularJS
- Sorting Rows By Table Header In AngularJS
- Creating Custom Filters In AngularJS
- ng-Hide And ng-Show In AngularJS
- ng-init Directive In AngularJS
- Search And MultiSearch In AngularJS
- ngInclude Directive In AngularJS
- $http Service In AngularJS
- Consuming ASP.NET WebService In AngularJS
- AnchorScroll Service In AngularJS
When we run the application, we see the local route i.e our localhost and students.

At the moment, when we click on students' links, we see a local route as student and we are displaying list of students. Here, we will display a hyperlink on each of the students and display various details of each student.
To achieve this, we are going to add a web method to this, which is going to fetch the student details for each student. We will add that webmethod to our webservice.
So, we will create another webservice method called GetStudents and pass a parameter as id. And, we will pass that parameterized id in our SQL where condition as we are displaying records on the basis of where id=1 and so on. So, our code is for GetStudents web method is:
- [WebMethod]
- public void GetStudents(int id )
- {
- Student student = new Student();
- string cs = ConfigurationManager.ConnectionStrings["Test"].ConnectionString;
- using (SqlConnection con = new SqlConnection(cs))
- {
- SqlCommand cmd = new SqlCommand("select * from students where id=@id", con);
- SqlParameter param = new SqlParameter()
- {
- ParameterName = "@id",
- Value=id
- };
- cmd.Parameters.Add(param);
- con.Open();
- SqlDataReader sdr = cmd.ExecuteReader();
- while (sdr.Read())
- {
- student.id = Convert.ToInt32(sdr["id"]);
- student.name = sdr["Name"].ToString();
- student.gender = sdr["gender"].ToString();
- student.city = sdr["city"].ToString();
- }
- }
- JavaScriptSerializer js = new JavaScriptSerializer();
- Context.Response.Write(js.Serialize(student));
- }






Prasanna MuraliPosted Sep 5, 2016, 11:06 AM
Nice post......