In the previous article we had discussed about ng-repeat functionality so please walk through the below link about ng-repeat directive.
Now we are going to present here how to fetch form data using Angularjs and display in codeigniter view as follows.
Let’s create a database table name as registration as below.
Now lets us create codeigniter form for the above database table, now add ng-model directive attribute to all input fields in the form , and also add display form using ng-repeat directive in same codeigniter form as shown below.AngularJS: Up and Running
For above html form let’s create angular module and controller to insert and fetch the data from mysql database.
Using angular module create controller as ‘regController’ and post form data using http service , posted form data will passes as json data to codeigniter controller function , there we need to decode the json data and insert into mysql database table registration.
After insertion, let’s fetch data using codeigniter get method and store it in an array $arr_data .
Let’s use codeigniter foreach iteration to store individual data into array and finally pass $arr_data into json_encode(); now check the code below.
Here in the above controller function json encoded data is echoed, the converted data is returned to angular success function. Then by using ng-repeat directive we can display the data to codeigniter view.
Thanks for reading this article, for any queries please use comments section.