in this example the code works
but when i try to pass this on my server i have an error
ReferenceError: _ is not defined
this is the js code
// Declare app level module which depends on filters, and services
var app = angular.module('myApp', []);
function RegisterCtrl($scope, $location)
{
$scope.steps = [
'Step 1: Team Info',
'Step 2: Campaign Info',
'Step 3: Campaign Media'
];
$scope.selection = $scope.steps[0];
$scope.getCurrentStepIndex = function()
{
// Get the index of the current step given selection
return _.indexOf($scope.steps, $scope.selection);
};
// Go to a defined step index
$scope.goToStep = function(index)
{
if ( !_.isUndefined($scope.steps[index]) )
{
$scope.selection = $scope.steps[index];
}
};
$scope.hasNextStep = function(){
var stepIndex = $scope.getCurrentStepIndex();
var nextStep = stepIndex + 1;
// Return true if there is a next step, false if not
return !_.isUndefined($scope.steps[nextStep]);
};
$scope.hasPreviousStep = function(){
var stepIndex = $scope.getCurrentStepIndex();
var previousStep = stepIndex - 1;
// Return true if there is a next step, false if not
return !_.isUndefined($scope.steps[previousStep]);
};
$scope.incrementStep = function() {
if ( $scope.hasNextStep() )
{
var stepIndex = $scope.getCurrentStepIndex();
var nextStep = stepIndex + 1;
$scope.selection = $scope.steps[nextStep];
}
};
$scope.decrementStep = function() {
if ( $scope.hasPreviousStep() )
{
var stepIndex = $scope.getCurrentStepIndex();
var previousStep = stepIndex - 1;
$scope.selection = $scope.steps[previousStep];
}
};
}
what is the function of
$scope.goToStep = function(index)
{
if ( !_.isUndefined($scope.steps[index]) )
{
$scope.selection = $scope.steps[index];
}
};
why is the error???
you need the underscore library included in the head section of your html file, or if its a node app, as a module.
<script src="http://underscorejs.org/underscore-min.js"></script>
or if its server side code, do npm install underscore
in your project root and then you can do
var _ = require('underscore');