As a newcomer to Javascript and Angular, I am currently working on integrating AngularJS into my website. Despite watching tutorials from CodeSchool, Egghead, and others, I seem to be stuck at the very beginning.
My issue lies in retrieving JSON data from my server and displaying it on my website. Below is the code snippet I have been working on;
JS:
angular.module('nasuh',[])
.factory('MY', function($http){
return {
isimler: function() {
var alHemen;
var url = 'http://localhost/uzak/remote.php?callback=JSON_CALLBACK';
$http.get(url).success(function(data) {
alHemen = data;
});
return alHemen;
}
};
})
.controller('nbgCtrl', function($scope, $http, MY) {
$scope.mangas = MY.isimler();
})
HTML:
<html ng-app = "nasuh">
<body ng-controller = "nbgCtrl">
<div class="col s12 m6 l4" ng-repeat = "manga in mangas"> -----> Want to repeat
<div class="row">
<div class="col s5">
<a href="#" class="thumbnail">
<img src="/kapaklar/{{manga.kapak}}">
</a>
</div>
<div class="col s7">
<p>{{manga.ad}}</p>
<a href="" class="waves-effect waves-light btn"></a>
</div>
</div>
</div>
JSON:
[{"id":"1","ad":"Naruto","yazar":"Masashi KISHIMOTO","kapak":"naruto.jpg"},
{"id":"2","ad":"One Piece","yazar":"Eiichiro ODA","kapak":"one_piece.jpg"}]
Edit-1: I appreciate all the responses, but I believe I need to call the data in the controller like this;
.factory('MY',
return {
isimler: function() {
.................................
$scope.mangas=isimler();
This approach allows me to use the data multiple times, especially when using it with the ui-router extension.
$stateProvider
.state('icerik', {
url: "/icerik",
templateUrl: "icerik.html"
controller: $scope.mangas = isimler();
})