Skip to content

AngularJS and Codeigniter : Retrieve data from the database

Last updated on March 29, 2016

Here I would will like to show you how to use Angular JS in CodeIgniter and I will show you how to get data from the database in Codigniter using Angular JS.

view : angularjs_view.php







Arjunphp.com
 









S.no. Email
{{user.id}} {{user.email}}

Controller: Angularjs.php

load->helper(array('url'));
		$this->load->view('angularjs_view');
	}
	
	public function get_list() {
		$this->load->model(array('user_model'));
		$data = $this->user_model->getAll();
		$this->output->set_content_type('application/json')->set_output(json_encode($data));
	}
}

/* End of file Angularjs.php */
/* Location: ./application/controllers/Angularjs.php */

Model : User_model.php

load->database();
		$this->table_name = 'tbl_users';
	}
	
	public function getAll() {
		return $this->db->from($this->table_name)->get()->result_array();
	}

}

/* End of file user_model.php */
/* Location: ./application/controllers/user_model.php */

That’s it.

0 0 votes
Article Rating
Subscribe
Notify of
guest

16 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments