0

I'm trying to retrieve json data using Angular $http.get. But I'm getting undefined for the value.

My Json File is as below

[
    {
        "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"
    }
]

Script File

.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>

2 Answers 2

1

Change your JSON like this,

{ "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" }

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

Here is the working App

Sign up to request clarification or add additional context in comments.

Comments

0

You have a valid JSON and JSON provided by @Sajeetharan also is correct.

If you want to use your JSON only then change data as below:

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

It will resolve your issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.