Javascript 在angularjs中编写应用程序时,我有一个错误:sintaxis?
在这种情况下,代码起作用 但是当我试图在我的服务器上传递时,我有一个错误Javascript 在angularjs中编写应用程序时,我有一个错误:sintaxis?,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,在这种情况下,代码起作用 但是当我试图在我的服务器上传递时,我有一个错误 ReferenceError: _ is not defined 这是js代码 // Declare app level module which depends on filters, and services var app = angular.module('myApp', []); function RegisterCtrl($scope, $location) { $scope.steps = [
ReferenceError: _ is not defined
这是js代码
// 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];
}
};
}
它的功能是什么
$scope.goToStep = function(index)
{
if ( !_.isUndefined($scope.steps[index]) )
{
$scope.selection = $scope.steps[index];
}
};
为什么会出现错误?您需要在html文件的头部分包含下划线库,或者如果它是一个节点应用程序,则需要将其作为一个模块
或者,如果它的服务器端代码是,请在项目根目录中执行npm安装下划线
,然后您就可以执行以下操作了
var\=require('下划线')代码>您在html文件中引用了吗?为什么我需要下划线???给我一行需要下划线的代码}你有的每一行
。例如,.indexOf
,.isUndefined
等,天哪!我从不使用下划线