小编Joh*_*iss的帖子

Angularjs $资源无法使用从REST API返回的数组

我正在尝试学习angularjs,并试图将数据绑定到从Rest API返回的数组.我有一个简单的azure api返回一个人物对象数组.服务网址是http://testv1.cloudapp.net/test.svc/persons.

我的控制器代码如下:

angular.module("ToDoApp", ["ngResource"]);
function TodoCtrl($scope, $resource) {
$scope.svc = $resource('http://testv1.cloudapp.net/test.svc/persons', {
    callback: 'JSON_CALLBACK'
}, {
    get: {
        method: 'JSONP',
        isArray: true
    }
});
$scope.items = $scope.svc.get();
$scope.msg = "Hello World";
}
Run Code Online (Sandbox Code Playgroud)

我的HTML看起来像:

<html>
<head></head>
<body>
<div ng-app="ToDoApp">
    <div ng-controller="TodoCtrl">
         <h1>{{msg}}</h1>

        <table class="table table-striped table-condensed table-hover">
            <thead>
                <th>Email</th>
                <th>First Name</th>
                <th>Last Name</th>
            </thead>
            <tbody>
                <tr ng-repeat="item in items">
                    <td>{{item.Email}}</td>
                    <td>{{item.FirstName}}</td>
                    <td>{{item.LastName}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

问题:上面的html表格没有显示任何数据.我可以在Firebug中看到对api的调用,也可以看到来自api的JSON响应.我做错了什么导致数据绑定到REST api不起作用?

PS:JSFiddle演示此问题的地址是:http://jsfiddle.net/jbliss1234/FBLFK/4/

angularjs angularjs-ng-repeat

14
推荐指数
3
解决办法
5万
查看次数

是否有可能对流星进行双向数据绑定

我是meteor的新手.我正在寻找一种方法来执行模型/集合到模板之间的双向数据绑定.我的理解是,当集合的内容发生变化时,模板会对此更改做出反应并自行更新.但是,如何在用户键入时自动收集,例如,在文本框中?

meteor

13
推荐指数
1
解决办法
6511
查看次数

Meteor + AngularJs的例子

我是Meteor和AngularJs的新手.我试图按照https://github.com/lvbreda/Meteor_angularjs上的示例应用程序,但到目前为止我还没有能够使它工作.

我在这段代码中收到错误'app is not defined':

app.controller('MeteorCtrl', ['$scope', '$meteor', function ($scope, $meteor) {
Uncaught ReferenceError: app is not defined
    $scope.todos = $meteor("todos").find({});
    $meteor("todos").insert({
        name: "Do something",
        done: false
    });
Run Code Online (Sandbox Code Playgroud)

我试着重写上面的内容:

var MeteorCtrl = function ($scope, $meteor) {
    $scope.todos = $meteor("todos").find({});
    $meteor("todos").insert({
        name: "Do something",
        done: false
    })
};
Run Code Online (Sandbox Code Playgroud)

仍然抛出错误'错误:未知提供商:$ meteorProvider < - $ meteor'

https://github.com/bevanhunt/meteor-angular-leaderboard上唯一的另一个米+角度示例似乎已过时.

有人可以使用https://github.com/lvbreda/Meteor_angularjs上的软件包发布一个简单但完全可以下载的meteor + angularjs示例吗?

angularjs meteor angular-meteor

12
推荐指数
3
解决办法
1万
查看次数