我想从配置文件加载所有URL.我创建了名为'config.json'的json文件,ConfigurationService.ts来按键获取URL.但我无法按键获取URL.
config.json:
{
"loginUrl": "http:example/login",
"verifyUrl": "http:example/verify"
}
Run Code Online (Sandbox Code Playgroud)
ConfigurationService.ts:
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Headers, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class ConfigurationService {
constructor(private http:Http) {}
private result: Object;
getConfiguration(key) {
return this.http.get('./app/config/config.json').map(res => {
res.json();
this.result = res._body;
return this.result[key]; //returns 'undefined', but when I return only 'this.result' it shows me all json data {...}
});
}
}
Run Code Online (Sandbox Code Playgroud)
auth_service.ts的一部分:
private x =this.configurationService.getConfiguration("verifyUrl").subscribe((result) => console.log(result));
Run Code Online (Sandbox Code Playgroud)
例如,我如何只收到loginUrl?
我有文件导出'item-state-manager.js':
module.exports.aggregate_states = function (member_states) {
console.log(member_states);
}
Run Code Online (Sandbox Code Playgroud)
其他文件应导入此模块并使用函数'aggregate_states':
var aggregate_states = require("./item-state-manager.js")
module.exports.saveItem = function () {
var aggregate = aggregate_states("state");
}
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
TypeError: aggregate_states is not a function
Run Code Online (Sandbox Code Playgroud)
我导入'item-state-manager.js'错了吗?
我想在成员数组中推送对象,如果它不存在。有没有办法检查对象是否不在mongodb的数组中?
{
_id: 1111,
members:[
{user_id: 11},
{user_id: 12},
{user_id: 13}
]
}
Run Code Online (Sandbox Code Playgroud)
所以我想检查一下:
newUser = {user_id: 14}
Run Code Online (Sandbox Code Playgroud)
不在成员数组中,如果不是 - 将其推到那里。被它困住了。预先感谢您的帮助。
尝试在 Tornado 中为 Web 身份验证编写测试。但接收错误:
C:\python3\lib\site-packages\tornado\testing.py:402: in fetch
return self.wait()
C:\python3\lib\site-packages\tornado\testing.py:323: in wait
self.io_loop.start()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <tornado.platform.select.SelectIOLoop object at 0x00B73B50>
def start(self):
if self._running:
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)raise RuntimeError("IOLoop is already running")
E RuntimeError: IOLoop 已经在运行
不知道该怎么办。需要帮助。这里是代码:
import pytest
import tornado
from tornado.testing …
Run Code Online (Sandbox Code Playgroud) 我不确定我做对了,但想做下一件事:通过客户端的 webSocket 连接发送文件,并保存在服务器上的某个目录中。如何使用nodejs保存它?
客户端:
<input type="file" id="myFile" multiple size="50" onchange="myFunction()">
<script type="text/javascript">
console.log('test');
var socket = new WebSocket("ws://localhost:8081");
socket.onmessage = function(event) {
var incomingMessage = event.data;
showMessage(incomingMessage);
};
function showMessage(message) {
var messageElem = document.createElement('div');
messageElem.appendChild(document.createTextNode(message));
document.getElementById('subscribe').appendChild(messageElem);
}
function myFunction(){
var x = document.getElementById("myFile");
var txt = "";
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select one or more files.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += …
Run Code Online (Sandbox Code Playgroud) 尝试了不同的方法.还是有错误的
GET http:// localhost:8080/node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js 404(未找到)
错误:XHR错误(404 Not Found)加载http:// localhost:8080/node_modules/ng2-bootstrap/ng2-bootstrap.js(...)
这是我的index.html:
<html>
<head>
<title>Angular 2 TypeScript Gulp QuickStart</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!-- Polyfill(s) for older browsers -->
<script src="lib/es6-shim/es6-shim.min.js"></script>
<script src="lib/zone.js/dist/zone.js"></script>
<script src="lib/reflect-metadata/Reflect.js"></script>
<script src="lib/systemjs/dist/system.src.js"></script>
<!--ng2-bootstrap-->
<script src="../node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<!--ng-bootstrap-->
<!--<script src="node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js"></script>-->
<script>
System.import('app')
.then(null, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是systemjs.config.js:
(function (global) {
// map tells the System loader where …
Run Code Online (Sandbox Code Playgroud)