【问题标题】:How can I use angularjs with xampp but without node.js for server communication?如何使用 angularjs 和 xampp 但没有 node.js 进行服务器通信?
【发布时间】:2016-03-12 23:12:18
【问题描述】:

我正在使用基本的 来编写 Web 应用程序 到目前为止,我一直使用

但现在我已经切换到

如果没有,我无法在任何地方看到服务器通信教程

因为我现在不习惯使用 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


【解决方案1】:

关键是,Angular JS 是一个客户端框架。在服务器端使用什么并不重要。

这是一个使用 PHP 进行服务器通信的示例。

http://www.w3schools.com/angular/angular_sql.asp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 2021-07-12
    相关资源
    最近更新 更多