【问题标题】:Use jSON data in AngularJS controller在 AngularJS 控制器中使用 JSON 数据
【发布时间】:2017-08-28 13:56:08
【问题描述】:

我在 Angular 中有一个这样的 json 列表:

vm.allnews = actualNews;

我在 console.log 上检查了它,它工作正常。通过数组列表获取所有新闻。 每个列表都有标题,我可以在 Angular 模板上拍摄:

<div class="card" ng-repeat="news in newsPage.allnews">

    {{news.title}}

..

而且它也有效。但我有一个表格,必须在数据中发送新闻标题,我试过这样:

 function sendTitle () {
var title = $scope.news.title;
..

但它得到了 'title undefined' 错误。 有什么问题?我该如何解决?谢谢。

【问题讨论】:

  • 你没有$scope.news,而是$scope.newsPage.allnews

标签: javascript angularjs json rest


【解决方案1】:

您需要从数组中发送一个带有相关对象的参数。

<div class="card" ng-repeat="news in newsPage.allnews">
   <div>{{news.title}}</div>
   <div ng-click="sendTitle(news.title)">Submit</div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多