【问题标题】:Angular - Getting JSON data as undefinedAngular - 获取未定义的 JSON 数据
【发布时间】:2016-01-08 05:01:37
【问题描述】:

我正在尝试使用 Angular $http.get 检索 json 数据。但我的价值是不确定的。

我的 Json 文件如下

[
    {
        "BannerText": "The First Mobile SSP. Truly Optimized for Outstream Video",
        "IntroText": "Chololate SSO provides necessary infrastructure for app monetization thgough video ads. More than 150 million people worldwide see a Chocolage SSP ad each month.",
        "SolutionHeaderText": "Solution For Publishers",
        "SolutionValueText": "Unlock the true potential of your mobile inventory with industry leading eCPMs & Fill Rates"
    }
]

脚本文件

.controller('HomeCtrl', function ($scope, $http) {
    alert('Called');
      $http.get("data/homeData.json")
        .success(function(data) {
          $scope.details = data;
          alert($scope.details.BannerText);
        });
    });

HTML

<div ng-controller="HomeCtrl">
    <div class="banner-section">
        <div class="banner-text text-center">
            <p>{{ details.BannerText }}</p>
        </div>
    </div>
</div>

【问题讨论】:

    标签: angularjs http get


    【解决方案1】:

    像这样改变你的 JSON,

    { “BannerText”:“第一个移动 SSP。真正针对外播视频优化”, “IntroText”:“Chololate SSO 通过视频广告为应用获利提供必要的基础设施。超过 1.5 亿人 全世界每个月都会看到一个 Chocolage SSP 广告。", "SolutionHeaderText": "出版商解决方案", “SolutionValueText”:“利用行业领先的 eCPM 和填充率释放您的移动广告资源的真正潜力” }

     <body ng-app='myApp' ng-controller='HomeCtrl'>
        <h1>Read Json from file </h1>
        {{entities.BannerText}}   </body>
    

    这是工作的App

    【讨论】:

      【解决方案2】:

      您有一个有效的 JSON,@Sajeetharan 提供的 JSON 也是正确的。

      如果您只想使用 JSON,请按以下方式更改数据:

      $scope.details = data[0];     // As it is an array so it should be in [0]
      

      它将解决您的问题。

      【讨论】:

        猜你喜欢
        • 2016-06-23
        • 2021-09-24
        • 2018-12-15
        • 1970-01-01
        • 1970-01-01
        • 2020-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多