0

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>
1
  • do you need any other html pages? Commented Oct 7, 2015 at 12:12

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.