1

I am creating a "word of the day" functionality in a web app and I have a JSON file with the following data structure. I couldn't get myself to dump 730+ entries into the HTML under ng-init to filter by day.

{"words":[ { "day":"0", "aramaic":"mi<u>t</u>ra", "english":"rain" }, { "day":"1", "aramaic":"libba", "english":"heart" }] }

I have the JSON file being called in the controller and trying to bring it in via scope.

$http.get('content/words.json').success(function(data) {
    var pairNum, prevPage, nextPage;    
    pairNum = 1;

        $scope.word = {
            all:data,
            day:parseInt(data.words[pairNum]["day"]),
            eng:data.words[pairNum]["english"],
            cha:data.words[pairNum]["aramaic"],
            limit:data.words.length
        }   

});

To my demise, I am unable to bring the JSON data to the HTML via $scope.word.all to filter. I would greatly appreciate help here, or a different way to architect this solution if I am approaching it wrong.

Here is how the HTML looks

<div class="row" ng-init="words = word.all">
<h2>CHALDEAN WORD OF THE DAY</h2>
<div class="small-2 columns"><a ng-click="word.day = word.day - 1"><span ng-show="word.day > 1" class="foundicon-left-arrow"> &nbsp;<span></a></div>
<div class="small-8 columns" ng-repeat="word in words | filter:word.day"><h4 class="wotd">{{word.english}} :: {{word.chaldean}} :: {{word.day}}<h4></div>
<div class="small-2 columns"><a ng-click="word.day = word.day + 1"><span ng-show="word.day < word.limit" class="foundicon-right-arrow"> &nbsp;<span></a></div></div><!-- .row -->

Thank you in advance to all that will attempt.

Ps. I already have a feeling I will be screwed with the <u> in the JSON.

1 Answer 1

1

Please have a look here : plnkr

html:

      <h2>CHALDEAN WORD OF THE DAY</h2>
    <div class="small-2 columns">
    <a ng-click="pairNum = pairNum -1">
    <span ng-show="pairNum > 0" class="foundicon-left-arrow"> previous <span></a></div>

    <div class="small-8 columns" ng-repeat="w in word | filter:{day:pairNum} ">
    <h4 class="wotd">
      {{w.english}} :
    : {{w.aramaic}} :
    : {{w.day}}
    <h4>

    </div>
    <div class="small-2 columns">
    <a ng-click="pairNum = pairNum + 1">
    <span ng-show="pairNum < word.limit-1" class="foundicon-right-arrow"> next <span></a>

</div></div><!-- .row -->

js:

    var app = angular.module('app', []);

    app.controller('MainCtrl', function($scope, $http) {

    $scope.pairNum = 0;
    $scope.words = [];

    $http.get('content/words.json').success(function(data) {

     angular.copy(data, $scope.words );

     });

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

1 Comment

Thank you, but the missing piece is still how to connect the JSON file to the scope. I am anticipating around 730 words.

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.