如何在Angular JS和Laravel中发布数据时解决$ injector:unpr

时间:2019-02-07 04:44:16

标签: angularjs json laravel api

我是angular js的新手。我尝试创建一个简单的页面来连接angular js和后端laravel数据库。我不断收到错误作为错误:$ injector:unpr 未知提供者。我不知道代码中出了什么问题。我希望有人能帮助我解决问题。预先感谢

Index.php

if (_itemCountElement != null && this.RowGroupInfo != null && this.RowGroupInfo.CollectionViewGroup != null)
{
        _itemCountElement.Text = string.Format(
                CultureInfo.CurrentCulture,
                this.RowGroupInfo.CollectionViewGroup.GroupItems.Count == 1 ? Properties.Resources.DataGridRowGroupHeader_ItemCountSingular : Properties.Resources.DataGridRowGroupHeader_ItemCountPlural,
                this.RowGroupInfo.CollectionViewGroup.GroupItems.Count);
 }

1 个答案:

答案 0 :(得分:0)

使用了错误的工厂名称,即评论而不是评论

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
</head>
<body ng-app="App">
    <div class="container" >
        <div ng-controller="Controller">
            <form name="form" ng-submit="submitComment()">
                <div class="form-group">
                    <label for="">Author</label>
                    <input type="text" class="form-control input-sa" name="author" ng-model="commentData.author">
                </div>
                <div class="form-group">
                    <label for="">Comment</label>
                    <input type="text" class="form-control input-sa" name="comment" ng-model="commentData.comment">
                </div>
             <button class="btn btn-sm btn-danger">Submit</button>
            </form>
        </div>
    </div>   
</body>
<script>
    angular.module('commentService',[])
    .factory('comment',function($http){
        return{
            save:function(commentData){
              return $http({
                method:"POST",
                url:'/api/comments',
                data:commentData
              })
            }
        }
    });
    var app = angular.module('App',['commentService']);
    app.controller('Controller',function($scope,comment){
          $scope.commentData={};
           $scope.submitComment=function(){
            Comment.save($scope.commentData);
          }
    });
 </script>
</html>