Hello to all. I have a problem to pass data from service to controller. If you help me I’ll much appreciate. Here is my code:
This is my Books factory in service.js
.factory('Books',function($http){
var books = [];
return {
all: function() {
$http({
method: 'GET',
url: 'http://localhost/webservice/server/?a=kitaplarim',
}).success(function(data){
books=data;
//on console i can see my books data
console.log(books)
return books;
}).error(function(data){
alert("Faill!!!");
});
}
}
});
controller.js
.controller('KitaplarimCtrl', function($scope, Books) {
$scope.books = Books.all();
//in here I cant see anything on $scope.books
console.log($scope.books)
})
Because of $scope.books didn’t assigned in my template file I can’t see the data
template
<ion-item class="list card" ng-repeat="book in books" type="item-text-wrap" href="#/tab/kitaplarim/?a=detail&id={{book.id}}">
<div class="item item-body">
<img ng-src="{{book.img}}">
<div class="bookInfoIndividual">{{book.name}}</div>
<div class="bookInfoIndividual">{{book.publisher}}</div>
<div class="bookInfoIndividual">{{book.author}}</div>
</div>
</ion-item> or paste code here