gpt4 book ai didi

javascript - 'book' 已定义但从未使用 MEAN 堆栈 Controller

转载 作者:行者123 更新时间:2023-12-03 11:17:33 26 4
gpt4 key购买 nike

我在创建变量并在 MEAN 包中使用它时遇到问题。我将其基于作为示例的“文章”包。我在客户端 Controller 中看到的所有内容都是相同的,但我不确定为什么当我尝试在“books”包而不是“articles”包上启动我的应用程序(使用 grunt)时捕获错误。

我还没有实现文章中的所有 Controller ,这可能是一个问题?

当我使用 grunt 启动应用程序时,出现以下错误:“book”已定义,但从未使用过 MEAN 堆栈 Controller

我相信错误出在 Controller 中,但如果您需要查看其他文件,请告诉我。

books.js

//client-side controller

'use strict';

angular.module('mean.books').controller('BooksController', ['$scope', 'Global', 'Books',
function($scope, Global, Books) {
$scope.global = Global;
$scope.package = {
name: 'books'
};

$scope.hasAuthorization = function(book) {
if (!book || !book.user) return false;
return $scope.global.isAdmin || book.user._id === $scope.global.user._id;
};

$scope.create = function(isValid) {
if (isValid) {
var book = new Books({
title: this.title,
author: this.author,
description: this.description,
seller: this.seller
});
/* Not sure if we need this location thing
book.$save(function(response) {
$location.path('books/' + response._id);
});
*/

this.title = '';
this.content = '';
this.description = '';
this.seller = ''; // or this.user implement
} else {
$scope.submitted = true;
}
};

}
]);

articles.js//这是我所基于的示例

'use strict';

angular.module('mean.articles').controller('ArticlesController', ['$scope', '$stateParams', '$location', 'Global', 'Articles',
function($scope, $stateParams, $location, Global, Articles) {
$scope.global = Global;

$scope.hasAuthorization = function(article) {
if (!article || !article.user) return false;
return $scope.global.isAdmin || article.user._id === $scope.global.user._id;
};

$scope.create = function(isValid) {
if (isValid) {
var article = new Articles({
title: this.title,
content: this.content
});
article.$save(function(response) {
$location.path('articles/' + response._id);
});

this.title = '';
this.content = '';
} else {
$scope.submitted = true;
}
};

$scope.remove = function(article) {
if (article) {
article.$remove(function(response) {
for (var i in $scope.articles) {
if ($scope.articles[i] === article) {
$scope.articles.splice(i, 1);
}
}
$location.path('articles');
});
} else {
$scope.article.$remove(function(response) {
$location.path('articles');
});
}
};

$scope.update = function(isValid) {
if (isValid) {
var article = $scope.article;
if (!article.updated) {
article.updated = [];
}
article.updated.push(new Date().getTime());

article.$update(function() {
$location.path('articles/' + article._id);
});
} else {
$scope.submitted = true;
}
};

$scope.find = function() {
Articles.query(function(articles) {
$scope.articles = articles;
});
};

$scope.findOne = function() {
Articles.get({
articleId: $stateParams.articleId
}, function(article) {
$scope.article = article;
});
};
}
]);

最佳答案

$scope.create 函数中定义了 book

var book = new Books({

并且永远不要使用它。这就是您收到警告的原因。如果您想在开发中跳过 jshint 警告,请使用 grunt -f 或在 grunt 配置中允许未使用的变量(或 .jshintrc 如果您使用它)

关于javascript - 'book' 已定义但从未使用 MEAN 堆栈 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27267770/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com