hhs hhs - 6 months ago 222
SQL Question

Adding data into mysql database using Angularjs and ionic framework

I am new to ionic framework. In my app, i am trying to input something and when the user hits the add button i want it to save in my database. How do i define the controller for that? And what backend should i use for routing here? I am really confused here where to start. Please help me out. Any lead will be helpful. Here is my index.html

<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<body ng-app="starter">
The nav bar that will be updated as we navigate between views.
<ion-header-bar class="top">
<h1 class="Title">Ionic App</h1>
Add URL: <input>


Some receipes to get you started:

  1. create a view with form elements backed by a controller that holds an initial (model) value for every element.
  2. get familiar with "2-Way-Data-Binding" using the ngModel directive. This basically connects your form elements with the model values.
  3. in the controller create a function that for example saves your model to a DB (something like $scope.saveData(){...};)
  4. add the ngClick directive to your "save" button: <button ng-click"saveData()">Add</button> to call the function.
  5. Have a look at $http or $resource and learn about RESTful Webservices to connect to your backend.
  6. Implement a REST endpoint on your server that saves the data to the DB
  7. See here for a tutorial that will take you further. There are plenty of such tutorials on the web.

Good luck! :-)