I'm very new to AngularJs. I'm trying learning it. I am facing a problem but can't figured out what is the error.
I'm integrating AngularJs with SpringMVC. My problem is that data is comming from Spring controller but when i assign that data to array defined in angular controller. it do not copies to it.
This is my Angular controller
App.controller('productController',['$scope','productService', function($scope,productService){
var self=this;
var category={catId:null,catName:''};
self.categories=[];
self.categoriesForPrdouct= function(){
productService.getCategories().then(
function(commingData){
self.categories=commingData;
console.log(self.categories); //This line Prints Data
}, function (errResponse) {
console.error('Error while fetching Categories');
}
);
};
console.log(self.categories); // **This line do not prints the data.**
self.categoriesForPrdouct();
self.reset = function(){
category={catId:null,catName:''};
$scope.myForm.$setPristine(); //reset Form
};
}]);
The first console prints the data but the second console do not.
and Second is i want to show the data in dropdown which i wrote it like this
<select id="itemCategory" ng-model="productCtrl.category.catName" ng-option="productCtrl.category.catName for category in categories">
</select>
Is this correct or wrong. i am confused in this one.