I followed information on this answer But it doesn't work in my situation. Chrome Inspector console says "ReferenceError: dataResponse is not defined" maybe that is the problem?
I am trying to GET this JSON from url:
[{"app_id":1,"app_name":"oh yeeah","app_description":"desc","app_price":111,"is_activated":false,"video":"videolink"},{"app_id":2,"app_name":"oh yeaaaeah","app_description":"ewaewq","app_price":222,"is_activated":false,"video":"fuck off"},{"app_id":3,"app_name":"oh yeaaaeah","app_description":"ewaewq","app_price":333,"is_activated":false,"video":"fuck off"}] This is my javascript code
var appstore = angular.module('appstore', []); appstore.service('dataService', function($http) { delete $http.defaults.headers.common['X-Requested-With']; this.getData = function(callbackFunc) { $http({ method: 'GET', url: '/administrator/components/com_apps/loadAppsJson.php' }).success(function(data){ callbackFunc(data); }).error(function(){ alert("error"); }); } }); appstore.controller('app_Ctrl', function($scope, dataService) { $scope.apps = [ {app_id:1, app_name:'oh yeah', app_description:'$app_description', app_price:111, is_activated:false, video:'$videolink'}, {app_id:2, app_name:'oh yeah', app_description:'$app_description', app_price:111, is_activated:false, video:'$videolink'}, {app_id:3, app_name:'oh yeah', app_description:'$app_description', app_price:111, is_activated:false, video:'$videolink'}, ]; //$scope.apps = null; dataService.getData(function(dataResponse) { $scope.apps = dataResponse; alert(dataResponse); }); console.log(dataResponse); console.log($scope.apps); //get images thumbs for(app = 0; app <= $scope.apps.length-1; app++) { $scope.apps[app].thumb = ("000" + $scope.apps[app].app_id).slice(-3); } //separate apps to columns var columns = []; for (var i = 0; i < $scope.apps.length; i++ ) { if (i % 3 == 0) columns.push([]); columns[columns.length-1].push($scope.apps[i]); } $scope.columns = columns; }); My HTML view
<div ng-controller="app_Ctrl"> <div class="row"></div> <div class="row"> <div class="row" ng-repeat="apps in columns"> <div id="app_id_{{ app.app_id }}" class="col-lg-4" ng-repeat="app in apps | filter:search"> <div class="thumbnail" ng-class="app.is_activated ? 'activated' : ''"> <a href="{{ app.video }}/&hd=1&fs=1&width=90%&height=90%&resize_to=height&showinfo=0" class="app_video_stitok movie-video help-video" rel="prettyPhoto"></a> <a href="index2.php?option=com_apps&mode=detail&id={{ app.app_id }}" class="app_detail_link_absolute"><!-- --></a> <a href="index2.php?option=com_apps&mode=detail&id={{ app.app_id }}" class="app_detail_link"><img ng-src="/images/apps/app_images/{{ app.thumb }}_thumb.jpg" alt="{{ app.app_name }}" title="{{ app.app_name }}"></a> <div class="caption"> <h3><a href="index2.php?option=com_apps&mode=detail&id={{ app.app_id }}">{{ app.app_name }}</a></h3> <p class="app_price">{{ app.app_price }} €</p> <div style="clear:both;"></div> <p class="app_card_description">{{ app.app_description | limitTo:100 }}...</p> <a href="index2.php?option=com_apps&mode=detail&id={{ app.app_id }}" class="btn btn-primary">Info</a> <a href="{{ app.video }}/&hd=1&fs=1&width=90%&height=90%&resize_to=height&showinfo=0" title="video" class="movie-video help-video btn btn-info" style="display:inline !important; z-index: 100;" rel="prettyPhoto">Video <span class="glyphicon glyphicon-facetime-video"></span></a> <a href="index2.php?option=com_apps&mode=detail&type=ajax&id={{ app.app_id }}" class="btn btn-primary btn-activate" ng-class="app.is_activated ? 'btn-activated' : ''">{{ app.is_activated ? 'Aktivované' : 'Aktivovať' }}</a> </div> </div> </div> </div>
getDatafunction.{console.log('response : ' + data);}