Passing a value from an angular service to a php file

Active3 hr before
Viewed126 times

6 Answers


I'm trying to pass the parameter from my angular service to a PHP file, Why did Germany hurry to phase out nuclear energy usage increasing the risk of fossil power use and Russian gas dependency? , @lucasnadalutti Your are correct!!! I fixed the problem by declaring a new variable and assigning it with StudentId.StudentId which got me the value I needed to pass, thank you very much! – Enrique Martinez Oct 28 '16 at 19:54 , Is there any downside to paying off a mortage shortly before moving?

I'm trying to pass the parameter from my angular service to a PHP file

function SearchStudent(studentId) {
   return $http.get('app-data/search-student.php', {
         params: {
            studentId: studentId
      .then(function(response) {
load more v

//Crreating HTTP params
//e.g. http://localhost/api/something.php?title=value&content=value
let httpParams = new HttpParams()
   .set('title', this.createNewForm.controls['title'].value)
   .set('content', this.createNewForm.controls['content'].value);

//Then pass the Http params object to the http.get) method
this.http.get('http://localhost/api/something.php', {

//Accessing these parameters in PHP
$title = $_GET['title'];
$title = $_GET['content'];

JSON is a great way of transporting data, and it is easy to use within AngularJS, or any other JavaScript.,Example: On the server we have a file that returns a JSON object containing 15 customers, all wrapped in array called records.,The example above executes the $http service with an object as an argument. The object is specifying the HTTP method, the url, what to do on success, and what to do on failure.,If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:



      data | json

Create a service for file-upload component via command-ng g s file-upload/,Generate new component file-upload-ng g c file-upload/ ,Open src/app folder and start editing app.component.html file.<app-file-upload></app-file-upload>,Create a new angular app using following command-ng new angular-file-upload

ng new angular - file - upload
load more v

It can be useful even when not using jQuery with its CSS, but should not be used outside of the console. The reason being that when $compileProvider.debugInfoEnabled is set to false, calling .scope() on a DOM node will return undefined.,Many times you probably hear that it’s not recommended to use jQuery with AngularJS, and that it should be avoided. It is imperative to understand the reason behind these statements. There are at least three reasons, as far as I can see, but none of them are actual blockers.,there does not seem to be a general rule for how many workers to spawn. Some developers claim that 8 is a good number, but use an online calculator and suit yourself,Notice the jQuery $destroy event. It is called like the AngularJS one, but it is handled separately. Scope $watchers will not react to the jQuery event.

DebugInfoEnabled is a setting which defaults to true, and allows for scope access through DOM nodes. If you want to try that through the JavaScript console, select a DOM element and access its scope with:

load more v

Now that you've created the RESTful API with a PHP script, you can proceed to create your Angular 9 project.,On the ngOnInit() method of the component, let's call the readPolicies() method of ApiService to get the policies:,You can access the frontend application by pointing your browser to the http://localhost:4200 address.,Let's now, create an Angular 9 service that will encapsulate all the code needed for interfacing with the RESTful PHP backend.

$ npm install - g @angular / cli
load more v

Other "angular-passing" queries related to "Passing a value from an angular service to a php file"