【发布时间】:2016-03-12 23:12:18
【问题描述】:
我正在使用基本的xampp 来编写 Web 应用程序 到目前为止,我一直使用php。
但现在我已经切换到angularjs
如果没有nodejs,我无法在任何地方看到服务器通信教程
因为我现在不习惯使用 nodejs,所以我想直接将 angularjs 用于 Web 应用程序;比如获取数据并将其添加到数据库中。
<body id="index" ng-app="notesApp" >
<h1>Hello servers!</h1>
<div ng-controller="maincntrl as cntrl" ng-repeat="todo in cntrl.items" class="item">
<div><span ng-bind="todo.label"></span></div>
<div>- <span ng-bind="todo.author"></span></div>
</div>
<script>
angular.module('notesApp',[])
.controller('mainCntrl',['$http', function($http){
var self= this;
self.items = [];
$http.get('/api/note').then(function(response){},function(errResponse){
console.error("error while fetching note");
});
}]);
</script>
</body>
此代码无效
【问题讨论】:
-
你不能使用angular直接访问数据库(因为它是客户端),你可以在服务器上使用php或node。话虽如此,如果您没有节点方面的经验,您可以使用 php 从 angular 端进行 ajax 调用。你可以看看我的文章,我在 php 中使用了 angular。 goo.gl/6BPmXw
标签: xampp php angularjs nodejs angularjs node.js web-applications xampp