JRun
JRun

Reputation: 3428

Basic Angular JS refresh and keeping session

This is a noob question, I understand very little about JS and Angular. (this is the first time I touch either). But I need to get this thing working and I appreciate your help.

I have the script / HTML below, and it kinda works. But two things are missing: 1) It creates a new session for every refresh 2) It filters on 'facebook-post' and I want it to filter on 'facebook-post' or 'twitter-message'.

Please don't '-1' the question for being too basic (and it is..) but I've spent a whole day trying to solve it myself first. I realize I need to spend a few days to learn JS and Angular, I don't have a few days right now.

Any help would be appreciated.

PS, while touching the subject: What's the quickest way to learn JS and Angular? and I mean quick.. ;-)

THANK YOU!

HTML: ...

    < div ng-controller="getMessages ">  
     < ol>  
        < li ng-repeat="message in messages  | filter:{'object-type':'facebook-post'}">  
        < div class="message">  
            < div class="icon"><img src="{{message['icon-url']}}" alt="" /></div>  
            < div class="text">{{message.text}}</div>  
            < div class="clear"></div>  
        < /div>  
        < /li>  
     < /ol>  

JS:

    function getJsonData($scope, $http, $filter) {
    $http({
        url : "some-url",
        dataType : 'jsonp',
        crossDomain : 'true',
        method : 'GET',
        data : {},      
        headers : {
            "Content-Type" : "application/json"
        }
    }).success(function(data, status, headers, config) {

        $scope.messages = data; //update_messages(data, $filter);

    });
    }

function getMessages($scope, $http, $timeout, $filter) {
    // initial call on load of page
    getJsonData($scope, $http, $filter);
    // polled call in specific intervals
    var poll = function() {
        $timeout(function() {
            getJsonData($scope, $http, $filter);
            poll();
        }, 10000);
    };
    poll();
}

Upvotes: 0

Views: 1047

Answers (1)

Gruff Bunny
Gruff Bunny

Reputation: 27976

For point number 2 you can use a filter function:

View:

<li ng-repeat="message in messages  | filter:socialMedia">

Controller:

$scope.socialMedia= function(media){
   return media == 'facebook-post' || media == 'twitter-message';

};

Not sure I understand question number 1 about the multiple sessions.

As for learning angular I quite like ng-book and Pluralsight have a number of good courses (I have no affiliation to either but they helped me get up to speed).

Upvotes: 1

Related Questions