Tag: angular2 services

如何从发送来自Angular 2的HTTP发布请求的节点服务器发送图像文件名的图像

我想从节点服务器下载图像文件名称发送请求后的图像,但我无法获得保存对话框或直接下载。我有一个文件夹上传,我想读取图像和下载。我是尝试粘贴在这里的代码。请帮助我一个很好的解决scheme。 router.post('/download', urlencodedParser, function(req, res) { var img = path.resolve('uploads/' + req.body.file); var filename = path.basename(img); var mimetype = mime.lookup(img); console.log(filename); console.log(mimetype); res.setHeader('Content-disposition', 'attachment; filename=' + filename); res.setHeader('Content-type', mimetype); var filestream = fs.createReadStream(img); filestream.pipe(res); res.on('finish', function(){ console.log("Download complete"); }); })

用于angular度2/4项目的自定义日志文件

我需要添加一个日志文件到我的angular2项目存储信息,错误日志文件如log.txt文件如何创build服务,创build和写入日志文件使用打字稿

从angular2服务发送正文中的值

我有一个Angular2服务 logIn (username, password): Observable<User[]> { return this.http.get(this.getUserUrl + username + '/' + password) .map(this.extractData) .catch(this.handleError); } 它发送一个请求 router.get('/authenticate/:username/:password', function(req, res, next) { schema.User.find({ username: req.param("username"), password: req.param("password")}).exec(function (err, users) { if (err) return console.error(err); console.log("Load success: ", users); res.send(users); }); }); 但我需要一种方式来发送username ,尤其是password的方式,而不是暴露给请求本身

使用angular度服务传递json数据

我一直试图通过json请求使用angular2服务发布数据到节点API。但是,当我通过参数彻底angular2服务时,我的节点API接收undefined值。 下面是我的angular度服务代码 enrolldegree(name,depart,enrollnumber,cgpa,university,token){ let peer = '["localhost:10151","localhost:10351"]'; let fcn = 'initDegree'; let argument = '["'+name+'","'+depart+'","'+enrollnumber+'","'+cgpa+'","'+university+']'; let headers = new Headers({'cache-control':'no-cache', 'Content-Type': 'application/json', 'authorization':'Bearer '+token}); let options = new RequestOptions({ headers: headers }); let body1 = new URLSearchParams(); body1.set('peers','["localhost:10151","localhost:10351"]'); body1.set('fcn',fcn); body1.set('args',argument); let body = JSON.stringify(body1); console.log('server logs',body); return this.http.post('http://localhost:4000/channels/mychannel/chaincodes/mycc', body, options ) .map((res: Response) => res.json()) […]

Angular2Fire安装错误

每当我试图安装使用npm的angular2消防模块,我得到以下错误: npm ERR! Windows_NT 10.0.14393 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "angularfire2" "firebase" "–save" npm ERR! node v6.11.0 npm ERR! npm v3.10.10 npm ERR! path E:\abcd\node_modules\.staging\base64url-fd6cd85c npm ERR! code EPERM npm ERR! errno -4048 npm ERR! syscall rename npm ERR! Error: EPERM: operation not permitted, rename 'E:\abcd\node_modules\.staging\base64url-fd6cd85c' -> 'E:\abcd\node_modules\firebase\node_modules\base64url' npm ERR! at destStatted […]

Angular 2 – 使用Windows身份validation消费平静的API调用

我有一个.net Web API托pipe在使用Windows身份validation的远程服务器上的IIS 7上。 我想要使用TypeScript和节点来访问使用Angular 2的web api。 早些时候,我得到一个错误'对预检请求的响应没有通过访问控制检查:没有'访问控制允许来源'标题出现在请求的资源' 我在托pipe的应用程序的web.config中添加了这个 <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> 但是现在我得到了未经授权的401错误。 我已阅读有关添加以下代码,以允许跨域访问 – 但我不知道我在哪里添加angular2应用程序,以及如何编译。 app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }); app.get('/', function(req, res, next) { // Handle the get for this route }); app.post('/', function(req, res, next) { // Handle the post […]