I am a beginner at Javascript and Angular, and I'm trying to implement AngularJS on my website. I have watching tutorials on CodeSchool, Egghead etc. But I am stack at very beginning.
Getting JSON data from my server and displaying it on my website. Here is my code;
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: Thank you all for your responses but I think I need calling data at the controller like;
.factory('MY',
return {
isimler: function() {
.................................
$scope.mangas=isimler();
Because I need to use this data more than once and using it at ui-router extension.
$stateProvider
.state('icerik', {
url: "/icerik",
templateUrl: "icerik.html"
controller: $scope.mangas = isimler();
})