I'm having an issue with my controller.js file. I can't seem to access the value from the angular.forEach function, specifically the flagvalue isn't being retrieved. Is it because the scope of flagvalue ends when the forEach function completes? Can someone clarify this for me?
var foreach = angular.module('foreach',[]);
foreach.controller ('carcontroller', function($scope){
alert("inn");
$scope.carname = [{name:'polo'},{name:'BMW'},{name:'Audi'},{name:'Suzuki'}];
var array = $scope.carname;
$scope.addcar = function(){
alert(" innn");
var currentcarname = $scope.carname;
alert(currentmoviename);
angular.forEach($scope.carname,function(refer){
alert("in foreach loop");
var flagvalue;
alert(flagvalue);
if(currentcarname.toLowerCase() == refer.name.toLowerCase()){
alert("in foreach loop - if");
flagvalue = true;
return true;
}
alert(flagvalue);
return true;
});
if(!flagvalue) {
alert("in if again");
}
};
});