angularjs json data not loading through $httpBackend -
i making $http call service , responding json data using $httpbackend. load fails , below error message in console. works after refresh page few times.
syntaxerror: using //@ indicate sourcemappingurl pragmas deprecated. use //# instead jquery.min.js:1 error: http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js being assigned //# sourcemappingurl, has 1 "error: unexpected request: lookup/program-categories no more request expected $httpbackend@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular-mocks/angular-mocks.js:1179 sendreq@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:8181 $http/serverrequest@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:7921 qfactory/defer/deferred.promise.then/wrappedcallback@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:11319 qfactory/defer/deferred.promise.then/wrappedcallback@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:11319 qfactory/ref/<.then/<@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:11405 $rootscopeprovider/this.$get</scope.prototype.$eval@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:12412 $rootscopeprovider/this.$get</scope.prototype.$digest@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:12224 $rootscopeprovider/this.$get</scope.prototype.$apply@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:12516 done@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:8204 completerequest@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:8412 createhttpbackend/</xhr.onreadystatechange@http://<hostname>.amazonaws.com/ostnfe/app/vendor/angular/angular.js:8355 "
below code. service 'lookups' makes http call , controller 'searchctrl' adds values html scope.
var stubbedostnapp = angular.module('stubbedostnapp', [ 'ostnapp', 'ngmocke2e' ]); stubbedostnapp.run(['$httpbackend','$http',function($httpbackend, $http){ $http.get('../test/data/program-categories.json').then(function(data){ $httpbackend.whenget('lookup/program-categories').respond(data.data) }); $httpbackend.whenget(/^views\//).passthrough(); $httpbackend.whenget(/^\.\.\/test\/data\//).passthrough(); }]); var ostnapp = angular.module('ostnapp', [ 'ngroute', 'ostncontrollers' ]); ostnapp.service('lookups',['$http',function($http){ var programcategories = {}; $http.get('lookup/program-categories').then(function(data){ for(var i=0;i<data.data.length;i++){ var programcategory = data.data[i]; programcategory.selected = false; programcategories[programcategory.id] = programcategory; } }); this.programcategories = function(){ return programcategories; } }]); ostncontrollers.controller('searchctrl',['$scope', '$http', 'lookups', function($scope, $http, lookups){ //this gets displayed in html $scope.programcategories = lookups.programcategories(); }]);
so, if moving of mock outside of promise makes respond null
means mock not initialized when sending request. try preload before running application not wait response , make mock immediately.
Comments
Post a Comment