我正在尝试Angular.js的内联模板.我希望有一种方法可以在呈现html页面时通过打印到控制台来调试Angular对象.
内联模板将html模板放在脚本标记内.例如:
<script type="text/ng-template" id="/htmlpage.html">
<div class="page-header">
<h1>Title</h1>
</div>
<!-- everything else here is html too -->
</script>
Run Code Online (Sandbox Code Playgroud)
这很棘手,因为脚本标签内的东西不再是JavaScript了.所以我不知道如何使用内联模板打印到htmlpage.html内的控制台.
我已经尝试但是嵌套脚本标记失败了:
<script type="text/ng-template" id="/htmlpage.html">
<!-- html page template Angular stuff before is okay -->
<script>console.log("this line DOESN'T SHOW UP anywhere");</script>
<!-- html page template Angular stuff AFTERWARDS ALL FAIL-->
</script>
Run Code Online (Sandbox Code Playgroud)
我也试过抛出一个裸的console.log,因为它在一个脚本标签内.
<script type="text/ng-template" id="/htmlpage.html">
<!-- rest of html page template is okay -->
console.log("this entire line gets output as text on the html page");
<!-- rest of html page …
Run Code Online (Sandbox Code Playgroud) 对于MEAN堆栈,我正在学习Mongoose的save()函数,它接受回调.其API说明:
Model#save([options], [fn])
Saves this document.
Parameters:
[options] <Object> options set `options.safe` to override [schema's safe option](http://mongoosejs.com//docs/guide.html#safe)
[fn] <Function> optional callback
Run Code Online (Sandbox Code Playgroud)
我如何知道可选回调中的参数?API仅举例说明:
product.sold = Date.now();
product.save(function (err, product, numAffected) {
if (err) ..
})
The callback will receive three parameters
err if an error occurred
product which is the saved product
numAffected will be 1 when the document was successfully persisted to MongoDB, otherwise 0.
Run Code Online (Sandbox Code Playgroud)
我认为API应该说的可选回调如下:
[fn] <Function> optional callback with this structure:
function(err, theDocumentToBeSaved, [isSaveSuccessful])
Run Code Online (Sandbox Code Playgroud)
它可以像下面这样使用.请注意,第二个参数(文档)必须与调用save的文档相同. …
我读过的消息说明MongoDB的findOne()
速度要慢得多find().limit(1)
,但后来我也听说过了.实际上现在的真相是什么?
文章从2013年3月开始:"使用find()+ limit()要快得多,因为如果文件存在,findOne()将始终读取+返回文件.get()只返回游标(或不返回),只读取数据如果你遍历游标."
从2011年的SE回答:"如果检索到find().limit(1)文档,速度差异的数量级似乎消失了.而且,我无法使用MongoDB JavaScript驱动程序重现主要的速度差异.我最初使用基准测试MongoDB Java驱动程序."
我希望无论答案是什么,它都与使用Mongoose find().sort().limit(1)
和findOne()
.
我npm start
用来启动我的MEAN堆栈应用程序,但我想使用node-inspector来调试一些Mongoose.我知道我可以开始与节点检查node-inspector
,但我能替代node --debug app.js
与使npm start
工作在我的情况?
这是我的MEAN堆栈目录结构:
HTML views/
Angular.js public/javascript/
Express.js routes/
Node.js app.js
Mongoose js models/, connected in app.js
Mongo db connected in app.js
Run Code Online (Sandbox Code Playgroud)
有关更多信息,这是我的相关问题.
我在 Mongoose 中使用 Node.js 和 MongoDB。我正在通过 Node.js 连接到 Mongoose,
db = mongoose.connect('mongodb://localhost/my_database_name')
Run Code Online (Sandbox Code Playgroud)
如何在 node.js 中配置一次以在集合上创建索引?
我的应用程序的目录结构基于本教程:
HTML views/
Angular.js public/javascript/
Express.js routes/
Node.js app.js
Mongoose js models/, set up in app.js
Mongo db set up in app.js
Run Code Online (Sandbox Code Playgroud)
指导我如何在 Node.js 的 MongoDB 集合上提供索引。
我正在使用MEAN堆栈并在Mongoose中编写这些方法.我想知道我放在Mongoose模型文件中的内容有什么问题.我想使用Mongoose简单地打印出myModel集合中所有文档的列表.
myModel.methods.myMethod = function(cb){
this.model("Bids").find({}, 'myField', function(err, results){
if (err){console.log(err);return err;}
console.log("okay");
console.log(results);
})
this.save(cb);
}
Run Code Online (Sandbox Code Playgroud)
另外,我可以在Mongoose中编写什么代码来判断myModel集合是否为空?
教一个男人如何钓鱼比给他一条鱼更好......
因此,如果您可以建议我可以安装哪些调试工具(例如Express中间件),这将有助于我自我调试,这将非常有用.请在此处发布您的调试建议.
在成功完成关于带有 Postgres db 的 Heroku Python 应用程序的教程后,我根据现有代码,通过复制和粘贴现有模型及其表的函数和文件,在 Heroku 应用程序上创建了一个新模型。但我很难真正让 Heroku 在 Postgres 上远程创建表。经过一番尝试和错误后,我找到了以下答案。
设置:Heroku Python 在本地和远程运行,Heroku Postgres 仅远程运行。
javascript ×6
mongoose ×5
node.js ×5
mean-stack ×4
mongodb ×4
angularjs ×2
console ×1
debugging ×1
django ×1
heroku ×1
html ×1
jquery ×1
performance ×1
postgresql ×1
promise ×1
python ×1