I'm still learning AngularJS and I'm trying to (for example) switch the names on a regular interval. I've got most of the basic idea down but I'm running into problems with how Angular handles how information is shared I've tried this:
http://jsfiddle.net/nwz5krw4/1/ The core of the fiddle is this (where names is an array of names):
this.changeName = function($scope,names)
{
this.nameIndex++;
if ($scope.$parent.nameIndex > (names.size - 1))
{
$scope.$parent.nameIndex = names[0];
}
else
{
$scope.$parent.myName = names[$scope.$parent.nameIndex];
}
};
Oddly, that will load in the browser and give me the first name, then simply refuse to change Reading the console reveals that t. Another path I've taken based on How do I use $rootScope in Angular to store variables? is to create this:
app.run(function($rootScope){
});
And place my array of names in there as $rootScope.names. Obviously $rootScope is to be avoided where possible, but right now I'm just going for functionality. However, this, too, did not work. Passing $scope to the method resulted in $scope.names or $rootScope.names being undefined. I'm not yet "thinking in Angular" and need some mental translation to make the leap.