Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - how to display values from API at the frontend

(function(angular, undefined) {
    'use strict';
    angular
        .module('erste.cafe-erstecb', ['angular-nicescroll', 'truncate'])
        .factory('CafeErstecb', function($resource, urls) {
            return $resource(urls.articlesApi, {
                size: '10',
                lang: 'cs',
                tags: 'Inovace'
            }, {
                query: {
                    isArray: false
                }
            });
        })
        .directive('gridCafeErstecb', function(flash, CafeErstecb) {
            return {
                restrict: 'E',
                replace: true,
                link: function(scope) {
                    CafeErstecb.query(function(response) {
                        console.log(response);
                        //$scope.result = response;
                    });
                },
                templateUrl: 'app/cafe-erstecb/grid-cafe-erstecb.tpl.html'
            };
        });
})(window.angular);

I have problem to display my values from API at the frontend. Im using factory. Full API:
http://www.erstecorporatebanking.cz/api/v1/content/?size=20&lang=cs&tags=Inovace

like image 300
Markoo08 Avatar asked Apr 01 '26 15:04

Markoo08


1 Answers

This is a wild guess, but are you by any change trying to load the content via a page that runs on HTTPS?

I tried to run your code in jsfiddle.net (see https://jsfiddle.net/masa671/5vesyewz/) and it gives the following error:

Mixed Content: The page at 'https://fiddle.jshell.net/_display/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www.erstecorporatebanking.cz/api/v1/content?lang=cs&size=10&tags=Inovace'. This request has been blocked; the content must be served over HTTPS.

AND: the other problem is that you are missing ngResource.

UPDATE:

Here's another example for ng-repeat over the results: http://jsfiddle.net/masa671/bvcr949r/

Note that records is an object instead of an array, so it needs to be translated to an array first:

scope.records = $.map(scope.result.records,
    function(value, index) {
        return [value];
    });
like image 78
masa Avatar answered Apr 04 '26 05:04

masa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!