Can i receive data from a database with Angular? - php

I start a new project with the framework Angular, to try and learn how to use this framework,
in my project i want to do a list of people, with name, age, mail ... with informations from a database but i don't know if it's possible or not (if you have a tutorial ;) )

You want to use a Node.js backend and then use Express.js
The express backend will provide routes to which you can make HTTP requests from Angular.
The code within the routes will query your database and return the result in an HTTP response back to Angular like this:
Angular --- (HTTP request) ---> Node.js Express server --- (query DB) ---> DB
And reverse the arrows for the HTTP response.
This is industry standard.

Related

How To integrate Angular 4 With Php frontend (Existing Project) for page Rendering and backend Nodejs

i have to integrate Angular 4 in my existing Php(Codeigniter) Project but i am not able to find right way to integrate angular 4 . any one know this process.please Share
If you are using node.js for backend. You wont need Php. It will be just NodeJs and Angular.
Without NodeJS, You can use Php to write your APIs and have front-end in Angular which will call those APIs using HttpClinetModule.
If you want to use Angular4 you should remake the frontend in Angular4.
Then on your NodeJS backend create rest routeshttp://localhost:3000/tasks for example would return a JSON object.
Then connect to your NodeJS route (http://localhost:3000/tasks) (from angular) using HttpClientModule and it'll return a JSON object then return that data from your service to a component that you want to display the data in, and either subscribe to it in the component or use the async pipe to unpack the data.
P.S you could also use your current PHP project and make that into an API.

How do I pass php form data to an angular2 app?

I'm still quite new to angular2/4 so forgive me if I'm missing something obvious.
I am trying to update a booking process and we are doing this with angular2/4. Currently the booking process starts on a php website, once some basic information is filled out the angular app is supposed to take over. What I'm not sure of is how I'm supposed to take the form data from PHP and receive that data in my angular app.
There is an express.js back end for the angular app, but I don't understand how I would be able to post from the PHP site and return the result to the angular app.
Again sorry, I'm still new to angular so I'm not sure how I should approach this.
Create an API (http://localhost:8080/bookings/) in your existing PHP application which your angular app can access via a GET/POST request using angulars HTTP client. https://angular.io/guide/http.
Or
Alternatively, use the express backend to talk to the MySql DB / Or other DB that your php application is using. Use express as an API similar to the above or simply render the page with the data obtained from the DB. https://expressjs.com/en/guide/database-integration.html

How do I use Laravel with AngularJS?

I am trying to use Laravel with AngularJS and want to understand the best way to set up such a project.
Should I (A) have a single domain and consume an API from the Laravel project, or (B) have website.com and api.website.com and consume the API as if it were a 3rd party API?
I can see pros and cons for each, but what I can't get my head around is how routing would work with option A. I assume the initial routing would be via Laravel to display a top level view and then from that point onwards AngularJS would do the routing, but surely AngularJS and its routing are only initialized when the page loads. For example, if a user goes to a subroute without hitting the site root, no route on the Laravel side will exists for that and thus would it not respond with 404/Not Found?
What is the best setup for consuming my Laravel API within AngularJS?
I suggest to separate (your option b).
Front and back-end are totally separated
You can replace one of them without problems in the other
Use middleware, json responses and http status codes
Use a framework for back-end too (for example Laravel or Lumen)
About routes ...
Your back-end has its own routes (endpoints).
Your front-end has its own routes (totally different), but should send GET/POST/PUT etc. requests to the back-end. The back-end returns (json) response, which will be parsed by the front-end.
Develop both separately! So you can use the back-end for third party later.

linking android application to the mysql database phone and link the info as well

Hey guys im faced with a challenge of linking my localhost mysql/php when adding something in a form that form should also be linked with my android application.
ex. I have made a form for the admin whereby they could add a new bus route and it will be stored into their database using php mysql in localhost server now that new route should also be linked to my android application it should display the new route (My android application uses sqlite database so two different database here) so when users use the application when they search for new route it should also display as well
How can i go with that? any ideas please im really stuck in this
thank you
Well there are generally 2 approaches to follow when you want to 'Sync' your web database to your mobile database
Push Notifications: You could send a push notification to all your users, whenever a new route is added to the mysql db. When the notification is received by your app, (it's not necessary you show the notification to the user) you could just ping the server for the new route, or you can send the 'route' in the message part of the push notification if you can, and then add this new route to your sqlite database.
AccountManager: Using the AccountManager is the preferred method when you want to Sync your data. The AccountManager uses the SyncAdapter to Sync your apps data with it's cloud. When Android pings the servers of other apps for syncing, it pings your app's server too, and syncs your data. This method also takes care of issues like, if the internet connection was not working when it was intended to sync, so android will schedule the next sync soon.
To provide a good service, you should take a look at a client-agnostic API architecture.
In this architecture, you have a PHP/go/whatever-written API, that can or can not be REST (but it's reccomended), that will provide, given a HTTP petition, the desired result.
Using PHP in the simplest way, you should create different .php files, one for each action ( www.myserver.com/getRoutes.php, www.myserver.com/getRouteDetail?routeId=3), and make those PHP files query the MYSQL database and return (echo) XML / JSON / Raw text.
this should then be parsed by your mobile application, and added/updated to your SQLite database.

Submit form using webservice

I am building a form on my website. I want to save the details into some other database/website using some exposed web service from the other website. How can i do this. I have no idea about this. Can you give some steps on how to do it.
Are you looking to build the "client" end (server with the form), "server" end (webservice receiving details) or both?
Client can use php_curl or similar to send data to a REST webservice on the server
So something like this
User (fills out form) -> Frontend-server (PHP) -- [sends request with information] --> Backend-server (saved)
So a user would theoretically send to the frontend server data data data
The frontend server (PHP) uses curl to send the info to the backend server http://backend.server.com/heres-some-info.php?data=data%20data%20data
The backend server will save/process the data as appropriate
Assuming the website is with some hosting service (like godaddy.com), it will have support for MySQL database and a server side language - like PHP/Python, etc.
Make a form using the server side language which inserts values into the database.
Send data to the form from the app.

Categories