如何使用express和angular 2(打字稿)在待办事项列表中编辑标题

我使用express和Angular 2 – todo列表在web上创build我的第一个应用程序。 现在我有事件来添加新的任务,删除和更改checkbox,但我不知道如何编辑标题通过点击,例如,项目或button上的“ 编辑 ”。 Task.ts export class Task{ title: string; isDone: boolean; } 文件html tasks.component.html <div *ngFor="let task of tasks" class="todo"> <button class="delete icon"> <i class="material-icons">delete</i> </button> <button class="checkbox icon" (click)="updateStatus(task)"> <i class="material-icons">{{task.isDone ? 'check_box' : 'check_box_outline_blank' }}</i> </button> <span class = "title"> {{task.title}}</span> <div class="actions" (click)="deleteTask(task._id)"> <button class="delete icon"> <i class="material-icons">delete</i> […]

我在哪里在课堂上使用诺言错了?

我正在使用这个类如下 var user_class = function (body) { this.body = body; }; user_class.prototype.login = function () { var that = this; return new Promise((fullfill,reject)=>{ that.find_by_username() .then(that.user_exists) .then(that.check_credentials) .then(that.generate_token) .then(fullfill) .catch(reject); }); }; user_class.prototype.find_by_username = function () { var that = this; return new Promise((fullfill,reject)=>{ user_model .find({username: that.body.username}) .then((user)=>{ that.user = user; }) .then(fullfill) .catch(reject); }); }; […]

通知不会出现在应用程序的背景状态和死亡状态

我试图在上传post时将通知推送给应用的最终用户。 它在应用程序处于前景时工作正常,但当应用程序在后台或被杀害时不显示。 有什么办法来显示应用程序被杀害或在后台运行的通知。 这里是我使用的node.js代码 const functions = require('firebase-functions'); let admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendPush = functions.database.ref('/promos').onWrite(event => { var topic = "deals_notification"; let projectStateChanged = false; let projectCreated = false; let projectData = event.data.val(); if (((event.data.numChildren())-(event.data.previous.numChildren()))>0) { let msg="notification arrived" let payload = { notification: { title: 'Firebase Notification', body: msg, sound: 'default', badge: '1' […]

CORS POST请求返回空主体

正如从这个问题的后续阶段“ 使POST JSON请求从HTML脚本到另一个域中的Node.JS应用程序 ”,我实现了一个CORS POST请求: var request = new XMLHttpRequest(); var params = "parameter=test"; request.open('POST', 'http://localhost:3009/param_upload', true); request.onreadystatechange = function() {if (request.readyState==4) alert("It worked!");}; request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.send(params); 这是非常接近互联网的例子。 这是我在我的node.js服务器端的设置: app.use(cors()); var corsOptions = { origin: '*', credentials: true, allowedHeaders: ['*'], optionsSuccessStatus: 200 } 当然,我的app.post函数头里有cors(corsOptions)。 但不知何故身体是空的。 作为要求,我得到了一个很长的回应,里面没有testing文本。 我可能会错过一点,但环顾四周,找不到它。 如果有人帮忙,我会很高兴。

NodeJS API通过ID获取。 如何检测项目未find?

我正在开发一个GET端点来从数据库(dynamoDB)中获取元素。 我使用Swagger在我的api中定义数据模型。 这是我的控制器中的operationId方法: getInvoiceConfigById: function(req, res) { var myId = req.swagger.params.id.value; // InvoiceConfig is a dynamoDb model // providerId attribute is the unique key of the db table InvoiceConfig.scan('providerId') .eq(myId) .exec(function (err, config) { if (err) { console.log("Scan InvoiceConfig error"); throw err; } res.status(200).send(config); }); } 如果找不到id,我想发送404消息。 我在swagger-ui中注意到响应的主体是空的 Response Body [] 当在数据库中找不到id时。 如何在我的代码中检测到ID未find时? 我试图检查响应的主体是否为空: 如果(!(config.body)) […]

AWS Lambda(NodeJS)不允许http.request或https.request?

我试图从一个Lambda请求另一个API。 我发现使用NodeJS http和https模块允许GET请求,但任何其他(例如POST)不起作用; 同时POST是唯一的方法,我需要为我尝试调用的服务工作。 下面是一个Lambda执行GET并收到200响应的示例: const https = require('https') function handler(event, context, callback) { const options = { hostname: 'encrypted.google.com' } https .get(options, (res) => { console.log('statusCode:', res.statusCode); res.on('end', callback.bind(null, null)) }) .on('error', callback); } exports.handler = handler 这certificate他的请求是允许的。 但是,如果脚本尝试使用https(或https)lib /模块的.request()方法发出相同的请求,请求将永远不会结束,并且Lambda会超时。 const https = require('https') function handler(event, context, callback) { const options = { hostname: […]

在Node.js中使用SERIAL的外键违规

在继续使用cockroachdb示例为node.js使用sequelize orm构build应用程序时,我扩展了它以在模型之间添加关联。 主键是INT,通过unique_rowid()自动递增。 根据你的文档,这是你的SERIAL的实现。 同步我的模型后,我尝试使用以下代码创buildlogging: models.sequelize.sync({ force: true }) .then(function () { return models.Customer.create({ name: "Sample Customer" }) }) .then(function (result) { const id = parseInt(result.dataValues.id, 10) return models.Order.bulkCreate([ { subtotal: 100.00, customer_id: id }, { subtotal: 200.00, customer_id: id } ]) }) 当这运行,我得到“ error: foreign key violation: value [255737842446434300] not found in customers@primary [id] […]

与Webpack的ReactJS:未捕获的ReferenceError:需求未定义

以下是我的webpack.config.js。 在浏览器开发工具中,获取“Uncaught ReferenceError:require is not defined” 如果我删除“目标”:“节点”,然后错误“未捕获TypeError:fs.​​readFileSync是不是一个函数”被抛出。 var config = { entry: './main.js', output: { filename: './index.js', }, devServer: { inline: true, port: 8080 }, node: { fs: "empty" }, module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader', query: { presets: ['es2015', 'react'] } } ] }, target: 'node' } module.exports = […]

win.document.write('content'); 无法读取未定义的属性'写'

我试图通过JavaScript文件从电子打开一个新的窗口,它的工作原理,并打开新的窗口,但我不能写入HTML /文本到新文件。 我得到这个错误: 无法读取未定义的属性'写' 我简单的代码: var myWindow = window.open("", "myWindow", "width=300, height=200"); myWindow.document.write ('content'); 任何build议或其他方式? 这里是来自控制台的图像:

Firebase云端function无法正常logging

我正在创build一个社交应用程序,在这个应用程序中,朋友可以通过他们的地址簿find对方。 基本上,我有两个长长的电话号码列表,我想使用firebase-cloud-function来查找两个列表中的所有数字。 为此,我将用户的所有联系信息发布到Firebase实时数据库,并触发云function(.onWrite)。 云function获取所有刚刚发布的电话号码,然后检索我的数据库中所有经过validation的电话号码,然后需要交叉引用这两个列表以查找所有匹配的电话号码。 这是我的代码… exports.crossReferenceContacts = functions.database.ref('/cross-ref-contacts/{userId}').onWrite(event => { //if it already existed then this function triggered beacuse we are calling set(null) and thus we dont want to proceed if (event.data.previous.exists()) { console.log("PREVIOUSLY EXISTED. RETURN NULL!!!"); return null; } const userId = event.params.userId; const userContacts = event.data.val(); var contactsOnPhone = []; var contactsVerifiedInDatabase =[]; […]