Muhsin Mohamed Pc Muhsin Mohamed Pc - 4 years ago 114
AngularJS Question

How to pass URL parameter to controller

I need to pass a URL parameter to the controller. On the below URL, I need to pass the ID parameter to the controller.

http://localhost/branch/more.php?id=20

Pass the ID URL parameter to the controller that I have given below.

app.controller('customersCtrl', function($scope, $http) {
$http.get("message.php?id=").then(function (response) {
$scope.myData = response.data.message;
});


So, the message.php?id=Parameter ID Here must be like this.

Answer Source

Inject $routeParams in your controller like

 app.controller('customersCtrl', function($scope,$http,$routeParams) {
 var routeID = $routeParams.id;
 $http.get("message.php?id="+routeID).then(function (response) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download