Sorry, I'm new to AngularJs. I made an application that receives data from the service, and displays it in main.html. Before that, I used $scope. And everything worked. But with as controller syntax, the application does not work.
main.html:
<div ng-repeat="item in main.newItems">
<img src="{{item.min_img}}">
<div>{{item.name}}</div>
</div>
app.js
var shopApp = angular.module("shopApp",["ngRoute"]);
shopApp.config(['$routeProvider',function($routeProvider){
$routeProvider.when('/main',{
templateUrl:'/main.html',
controller:"mainCtrl",
controllerAs:"main"});
}]);
shopApp.controller("mainCtrl",function(newItemsFactory){
this.newItems=newItemsFactory.getNewItems().then(function success(response) {
this.newItems=response.data;
});
});
shopApp.factory('newItemsFactory',function($http){
return{
getNewItems:function(){
return $http({method: 'GET', url: 'newItems.json'});
}
}
});
newItems.json
[
{"min_img:1.png",name:"first"},
{"min_img:2.png",name:"second"},,
{"min_img:3.png",name:"third"},
]
Sorry for my bad Engish and Thank.