【问题标题】:AngularJs Data fetch from Laravel从 Laravel 获取 AngularJs 数据
【发布时间】:2015-02-05 16:19:06
【问题描述】:

你好,我使用 laravel 和 angular js

我正在从数据库中获取 1 个用户数据,但我无法在用户个人资料页面中显示我的用户数据

id = $rootScope.user.id

$http.get('api/users/'+id).success(function(data){


    $scope.user = data;


})

我可以在这样的 chrome 开发者工具中看到数据:

data: [{id: "308", email: example, first_name: "example", last_name: "example", website: null,…}]
status: 1

但是当我想像这样在 ng-model 中显示数据时

ng-model="user.first_name" 

我在视图中看不到数据

什么时候这样做:

ng-model="user"

返回是 [object 对象]

等待帮助,我的问题在哪里?

【问题讨论】:

    标签: javascript php angularjs laravel


    【解决方案1】:

    $scope.user 是一个包含 JSON 数据的数组。所以你不能像user.first_name一样访问first_name。它应该对你有帮助。

    <span ng-repeat="info in user">{{info.first_name}}</span>
    

    【讨论】:

    • 或者,更理想的是,您的 API 应该返回单个对象,而不是数组中的对象。
    猜你喜欢
    • 2014-12-29
    • 2015-04-04
    • 1970-01-01
    • 2015-11-14
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    相关资源
    最近更新 更多