0

我是 angularjs 和 php 的新手

我想从数据库中获取数据,

但出现错误“错误:未知提供者:$resourceProvider <- $resource <- Rdpservice”

代码

angular.module('remoteApp')
 .factory('Rdpservice', function ($resource) {
return $resource('connect.php', {}, {
  query:  {method: 'GET'},
  get:    {method: 'GET'},
  remove: {method: 'DELETE'},
  edit:   {method: 'PUT'},
  add:    {method: 'POST'}
});
});


<?php
  $con=mysqli_connect("localhost","user","password");
  if (mysqli_connect_errno())
 {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

 $sql="CREATE DATABASE my_db";
 if (mysqli_query($con,$sql))
 {
   echo "Database my_db created successfully";
 }
 else
 {
   echo "Error creating database: " . mysqli_error($con);
 }

 $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
 echo json_encode($arr);
 mysqli_close($con);
 ?>
4

1 回答 1

0

在我看来,您的应用程序中没有包含 $resource 服务。见这里:http ://docs.angularjs.org/api/ngResource

您需要“安装”它,但包括脚本(在上面的链接中找到),然后在您的模块中需要它,如下所示:angular.module('app', ['ngResource']);

于 2013-09-11T06:53:09.937 回答