Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <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>
  </head>
  <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>
    </ion-header-bar>
    <ion-content>
      Add URL: <input>
      <button>Add</button>
    </ion-content>
  </body>
</html>
share|improve this question
    
do you need any other html pages? – Muhsin Oct 7 '15 at 12:12
up vote 2 down vote accepted

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! :-)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.