添加数据转换成使用Angularjs和离子框架mysql数据库 [英] Adding data into mysql database using Angularjs and ionic framework
本文介绍了添加数据转换成使用Angularjs和离子框架mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的离子的框架。在我的应用程序,我想输入的东西,当用户点击添加按钮,我希望它在我的数据库保存。我如何定义控制器?而且我应该使用什么后端路由吗?我真的在这里混淆从哪里开始。请帮助我。任何铅会有所帮助。这里是我的index.html
<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
<间的charset =UTF-8>
< META NAME =视CONTENT =初始规模= 1,最大规模= 1,用户可扩展性=无,宽度=设备宽度>
<标题>< /标题> <链接HREF =LIB /离子/ CSS / ionic.css的rel =stylesheet属性>
<链接HREF =CSS / style.css文件的rel =stylesheet属性> <! - 如果使用萨斯(运行一饮而尽SASS第一),然后在下面取消注释并取下上面的CSS包括
<链接HREF =CSS / ionic.app.css的rel =stylesheet属性>
- > <! - 离子/ angularjs JS - >
<脚本SRC =LIB /离子/ JS / ionic.bundle.js>< / SCRIPT> <! - 科尔多瓦脚本(这将是开发过程中一个404) - GT;
&所述; SCRIPT SRC =cordova.js>&下; /脚本> <! - 您的应用程序的JS - >
<脚本SRC =JS / app.js>< / SCRIPT>
<脚本SRC =JS / controllers.js>< / SCRIPT>
<脚本SRC =JS / services.js>< / SCRIPT>
< /头>
<机身NG-应用=启动器>
<! -
导航栏,因为我们之间意见的导航将被更新。
- >
<离子头吧级=顶>
< H1类=标题>离子应用< / H1>
< /离子头吧>
<离子含量>
添加网址:<输入>
<按钮>添加< /按钮>
< /离子含量>
< /身体GT;
< / HTML>
解决方案
有些receipes让你开始:
- 创建与保存每个元素的初始(模型)值控制器支持的表单元素的视图。
- 熟悉2-WAY-数据绑定使用 ngModel 指令。这基本上连接的表单元素与模型值。
- 在控制器创建一个函数,例如保存您的模型,以一个DB(类似
$ scope.saveData(){...};
) - 添加 ngClick 指令的保存按钮:
<按钮NG单击保存数据()>添加< /按钮方式>
来调用函数 - 看一看 $ HTTP 或的 $资源和了解的RESTful Web服务连接到后端 。
- 实施您的服务器上REST端点的数据保存到数据库
- 请参见这里一个教程,将带你进一步。有很多这样的教程在网络上。
祝你好运! : - )
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>
解决方案
Some receipes to get you started:
- create a view with form elements backed by a controller that holds an initial (model) value for every element.
- get familiar with "2-Way-Data-Binding" using the ngModel directive. This basically connects your form elements with the model values.
- in the controller create a function that for example saves your model to a DB (something like
$scope.saveData(){...};
) - add the ngClick directive to your "save" button:
<button ng-click"saveData()">Add</button>
to call the function. - Have a look at $http or $resource and learn about RESTful Webservices to connect to your backend.
- Implement a REST endpoint on your server that saves the data to the DB
- See here for a tutorial that will take you further. There are plenty of such tutorials on the web.
Good luck! :-)
这篇关于添加数据转换成使用Angularjs和离子框架mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文