javascript - Angular http get not working -


i'm doing testing api in apiary.io , wanted call data angular, doesn't seem call correctly. should pretty simple, i'm not sure whats wrong:

html:

<span><a href="network-updates.html">{{user.text}}</a></span> 

js:

 var maincontroller = function($scope, $http){   var usercomplete = function(response){   $scope.user = response.data;   };    $http.get("http://private-abc123-.apiary-mock.com/bus") .then(usercomplete);    }; 

json:

{    "header" : "heading", "text" : "hello" } 

this works me out of box try: (this solution no longer correct, see update below)

var = angular.module('a', []);  a.controller('dbctrl', ['$scope', '$http', function ($scope, $http) {  $scope.loaddata = function () {     $http.get("url")         .success(function(data){             $scope.data = data; //return if success on fetch         })         .error(function() {             $scope.data = "error in fetching data"; //return if error on fetch         });     };      $scope.loaddata(); //return loaddata function  }]); 

update:

var = angular.module('a', []);  a.controller('dbctrl', ['$scope', '$http', function ($scope, $http) {  $scope.loaddata = function () {     $http.get("url")         .then(function(data){             $scope.data = data; //return if success on fetch         }, function() {             $scope.data = "error in fetching data"; //return if error on fetch         });     };      $scope.loaddata(); //return loaddata function  }]); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -