CRUD Application with AngularJS

11:35:00 AM


This tutorial will teach you how to create a CRUD Application using AngularJS,PHP,MySQL and Slim framework.
You can find the source code of this article here
AngularJS is a Java Script framework for dynamic web apps.It lets you extend HTML tags.
Slim is a PHP micro framework which we are going to use for create REST service in php.

Below you can find file structure of the Application.
  • js - This folder include all the JavaScript files we use here.
  • api - This folder will contain Slim framework.
  • pages - This folder contains all the front end pages.
well let's get started with Installing Slim framework inside api folder . Follow the link, If you have any doubts over how to installing it. It's fairly easy process and I am not going write it in detail here.
After installing Slim you'll get a folder call Slim inside api folder.we'll leave it there for the current been.
Next create the index.html file and put below code segment inside it.

Well lets go through this code. We load AngularJS to our app and remember we have to load the angular-route.js too.I will tell you why later in this tutorial. Optionally I load bootstrap style sheet to have to have some sort of user friendly front end
<body ng-app="Application">
You can say this as a starting point of a Angular Application. ng-app directive responsible for auto-bootstrap angular application.
<div ng-view></div>
This directive is simply responsible for View of the Application.

Now inside JS folder create app.js file.


Here we have our 'Application' module.
In First line we declare our module.In this case it's Application. Second argument is a array. It consist of dependencies for the module.Here we need 'ng-Route' since it is the module that responsible for provide routing and deeplinking services and directives for angular apps.
Rest of the code is for set routs for the App.$routeProvider use for configuring routes.I recommend you to go through above link to get a better understand about $routeProvider. Actually this is where we need above discussed 'ng-Route' module to be installed as a dependency for $routeProvider.

Lets we move on to create our first Controller.


This is the controller for get the list of customer details.

AngularJs application are controlled by Controllers. 'CustomerListControler' is a JavaScript function and $scope is the application object. Which means it owns the application variable and objects.
$http use to communicate with web servers.
$http.get is the function use to read the server data and those data will store in property call customers.

What we have here is Controller for add a new customer.
One of new thing we come across here is $location. $location service parses the URL in the browser address bar and makes the URL available to your application.Changes to the URL in the address bar are reflected into $location service & changes to $location are reflected into the browser address bar.

Then we move onto create 'CustomerEditController', The Controller that will responsible for handle Edit and Delete.


Hm..looks like we don't have anything new to discuss here. So we'll move on to create database handling section.
Go to index.php file inside Slim folder.

 In first two lines we call & create instance of Slim. Then comes the interesting part of Slim's route handling.As you can see it's really easy to understand .That is the one of main reason we use Slim framework here.If you want to know more about Slim routing follow this 

Then we'll create actual database connection & database handling.

Now we almost end.All you have to do is create frond end pages for add,update and  detailed list of customers.
Go to pages folder and create list.html,new.html and edit.html files
Well..It's done guys.Now we have your own little AngularJS application whichcapable of doing CRUD operation.I hope you enjoy the tutorial.
Happy coding.

You can find the source code of this article here

You Might Also Like

29 comments

  1. Hi Anjana,
    Great Tutorial, Really saved my time.
    Update is not working in mozilla, but its working fine in chrome. ny solution?

    ReplyDelete
    Replies
    1. hey, Sorry for the late reply. Really ? Actually i didn't test this out one firefox. but i am sure the core idea is same, It should be some designing issue. But I'll take a look at this.

      Delete
  2. Update is not working in mozilla, but its working fine in chrome. ny solution?

    ReplyDelete
    Replies
    1. hey, Sorry for the late reply. Really ? Actually i didn't test this out one firefox. but i am sure the core idea is same, It should be some designing issue. But I'll take a look at this.

      Delete
  3. Great tutorial
    But download link for sourcecode doesn't work. Could you fix it ?
    Thanks Anjana.

    ReplyDelete
    Replies
    1. Sorry for the late reply it seems working fine for me

      Delete
  4. Great tutorial.. thank you for sharing, Anjana..

    ReplyDelete
  5. Good job, but I couldn't download the source code. Pls can you send the source code to my email: olasam4liv@gmail.com. Thanks

    ReplyDelete
    Replies
    1. Sorry for the late reply it seems working fine for me

      Delete
  6. I have a quick question. When I try to use the api to add a new Customer (/api/New_Customer), I get the follow error. Any ideas as to why or how I can fix it?

    {"error":{"text":SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Username' cannot be null}}

    ReplyDelete
    Replies
    1. It seems like you did not pass the username to the databse. what is your database structure ? is username is a not null column in it ? anyway your error is popping out because of a SQL query issue. not a Angular one. :)

      Delete
  7. Good job, but I couldn't download the source code. Pls can you send the source code to my email: sundarsl1991@gmail.com. Thanks

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. CodeIgniter CRUD App with AJAX Bootstrap.
    http://www.phpcodify.com/codeigniter-crud-using-ajax-bootstrap-models-and-mysql/

    ReplyDelete
  10. Hi,
    I am working with same tutorial but could not understand how to upload image using angularjs with slim php rest api. Can anyone help me here on this topic?

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Hi there,

    Check out this blog, full angularjs CRUD with pagination sorting and filter using codeigniter as backend framework

    You can even download and run on your local system. here is the link

    https://angularjscrudpagination.blogspot.com/

    ReplyDelete
  13. This is an one of the excellent blog.I liked your way of presentation.I gained some Information.
    Angular JS Online training
    Angular JS training in Hyderabad

    ReplyDelete
  14. python training
    angular js training
    selenium trainings
    sql server dba training
    <a href="https://www.kitsonlinetrainings.com/course/Application packging online training > application packging training</a>

    ReplyDelete
  15. Explore top-notch Docker consulting services to optimize containerization strategies. Unlock efficiency and seamless deployment for your business success.

    ReplyDelete

Popular Posts