1

I am using ajax (via AngularJS) to grab a Google calendar feed and list the latest events on my homepage. This works great, however, Google seems to append the string "Event Status: confirmed" to the events listing at the end of the date. This is what it looks like:

enter image description here

I can't seem to hide "Event Status: confirmed" from the feed. Is there a way I can use AngularJS filter to remove that string from my JSON feed?

The "Event Status: confirmed" text is coming from the event.summary.$tproperty in the JSON feed. This is what the actual property value looks like:

"$t": "When: Sun Nov 15, 2015<br />\n\n\n<br />Event Status: confirmed""

Here's my HTML with AngularJS ng-repeat directive looping through the feed:

<section id="calendarListing" class="col-lg-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Upcoming Events</h3>
                    </div>
                        <div class="panel-body" ng-controller="CalCtrl">
                        <ul class="list-unstyled" ng-repeat="event in events.feed.entry | reverse | limitTo: 3 ">
                    <li><h4 ng-bind-html="event.title.$t"></h4>
                        <span ng-bind-html="event.summary.$t"></span>
                    </li>    
                </ul>
                        </div>
                        <div class="panel-footer"><a href="calendar.php"><i class="fa fa-arrow-circle-right"></i> View full calendar</a></div>
                </div>
</section><!--/events-->

Here is my script:

var calApp = angular.module("calApp", ['ngSanitize']);
var feedUrl = 'https://www.google.com/calendar/feeds/ogmda.com_89pas0l9jbhpf053atd83hdj30%40group.calendar.google.com/public/basic?alt=json';

calApp.filter('reverse', function() {
  return function(items) {
    return items.slice().reverse();
  };
});

calApp.controller('CalCtrl', function($http, $scope) {
    $http.get(feedUrl).success(function(data) {
        $scope.events = data;
        console.log(data);
        });
});

angular.element(document).ready(function() {
    angular.bootstrap(document.getElementById("calendarListing"),['calApp']);
});
6
  • 1
    what does the actual html look like? Should be able to do this with css Commented Oct 25, 2015 at 22:32
  • Can you give an actual example of what the JSON looks like for that $t property? Commented Oct 25, 2015 at 22:33
  • This is what the actual example looks like: "$t": "When: Sun Nov 15, 2015<br />\n\n\n<br />Event Status: confirmed" Commented Oct 25, 2015 at 23:41
  • I think you should migrate to using APIv3 or an ICS file as these feeds are going away on Nov 18th: support.google.com/calendar/answer/6285065 Commented Oct 29, 2015 at 17:01
  • Is the JSON going away, too? Looks like only the XML is. Commented Oct 29, 2015 at 22:45

1 Answer 1

1

I'd probably just go with a CSS solution. Seems easier that trying to parse out the text. Something like

<span class="eventSummary" ng-bind-html="event.summary.$t"></span>

and in CSS

.eventSummary {
    display: block; /* or inline-block */
    white-space: nowrap;
    overflow: hidden;
    height: 1.3em; /* or whatever your line-height is */
}

If you're still keen on actually removing the text, I'd go with a custom filter

.filter('singleLine', function() {
    return function(html) {
        var br = html.indexOf('<br');
        return br === -1 ? html : html.substring(0, br);
    };
})

and in your template

<span ng-bind-html="event.summary.$t | singleLine"></span>
Sign up to request clarification or add additional context in comments.

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.