我尝试通过Angular 2 Observable subscribe方法的例子来理解typescript的箭头函数.有人可以解释我:
我有这个代码有效:
this.readdataservice.getPost().subscribe(
posts => { this.posts = posts; }
);
Run Code Online (Sandbox Code Playgroud)
但如果我使用它,它应该是一样的吗?但这不起作用.
this.readdataservice.getPost().subscribe(
function (posts) {
this.posts = posts;
}
);
Run Code Online (Sandbox Code Playgroud) 我尝试在phonegap/cordova 3.0.0上运行我的原生android插件,但我不工作,
涟漪的错误:未捕获的ReferenceError:未定义炬
来自index.html的调用
<button onclick="torch.shine(200);">dummy</button>
Run Code Online (Sandbox Code Playgroud)
plugin.xml
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Torch">
<param name="android-package" value="org.holzi.torch.Torch"/>
<param name="onload" value="true" />
</feature>
</config-file>
<js-module src="www/torch.js" name="Torch">
<clobbers target="torch" />
</js-module>
<source-file src="src/android/Torch.java" target-dir="src/org/holzi/torch" />
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
</config-file>
</platform>
Run Code Online (Sandbox Code Playgroud)
插件的www文件夹中的torch.js
var exec = require('cordova/exec');
/* constructor */
function Torch() {}
Torch.shine = function() {
exec(
function(result){ alert('ok: '+reply); },
function(err){ alert('Error: '+err); }
, "Torch", "shine", ['200']);
}
var torch = new Torch(); …Run Code Online (Sandbox Code Playgroud) 我制作了一个 Angular 8.1.0 PWA,当我在我的移动设备上离线测试它时,资产组中的图像和字体没有加载。
这里是 chrome://inspect 从离线移动设备上安装的应用程序的徽标图像的示例错误,从 ngsw-worker.js:596 抛出
Uncaught (in promise) Error: Response not Ok (fetchAndCacheOnce): request for https://exampledomain.com/assets/logo.svg returned response 504 Gateway Timeout
at PrefetchAssetGroup.<anonymous>
Run Code Online (Sandbox Code Playgroud)
这里是 ngws-config.json
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
}, {
"name": "assets",
"installMode": "prefetch",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
这里是生产构建后的 ngws-config.json:
{
"configVersion": 1,
"timestamp": 1563173692955,
"index": "/index.html",
"assetGroups": …Run Code Online (Sandbox Code Playgroud) 我有以下代码来检查原始标头并允许访问,使用 express 和 npm cors 插件
const app = express();
const cors = require('cors')
var corsOptions = {
origin: function (origin: any, callback: any) {
if (!origin || whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
}
}
app.use(cors(corsOptions));
Run Code Online (Sandbox Code Playgroud)
现在我想知道是否有办法捕获“新错误”回调?
并发回 400 http 状态?
谢谢!
我尝试在按钮单击后将值设置为滑块,但它不起作用 - 滑块不移动.代码运行良好,没有错误.
它应该很简单,但我无法弄清楚.xCode版本4.5.2
谢谢!
我的代码:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *debugLabel;
@property (weak, nonatomic) IBOutlet UISlider *slider;
- (IBAction)slider:(id)sender;
- (IBAction)ButtonChangeValue:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize slider;
...
- (IBAction)slider:(UISlider *)sender {
float value = [sender value];
self.debugLabel.text = [NSString stringWithFormat:@"Value: %f",value];
}
- (IBAction)ButtonChangeValue:(id)sender {
slider.value = 90;
}
Run Code Online (Sandbox Code Playgroud) 我有一个 Angular PWA,它无法离线启动(http 错误 504)。当我检查 /ngsw/state 时,出现此错误:
Error: Hash mismatch (cacheBustedFetchFromNetwork): https://example.com/favicon.ico: expected 566d8535a3adc2f7210a8a890bdc50ec4f91f0e3, got 8e076950c4c615772d8d5d753e07377bab9f2f27 (after cache busting)
at PrefetchAssetGroup.<anonymous> (https://example.com/ngsw-worker.js:734:35)
at Generator.next (<anonymous>)
at fulfilled (https://example.com/ngsw-worker.js:174:62))
Latest manifest hash: 5952e5e67f8b4ee7115ef9d519a346712927b608
Run Code Online (Sandbox Code Playgroud)
使用 Angular CLI:9.1.9 节点:12.16.1 Angular:9.1.11
PWA 上的灯塔检查没有给我任何错误,并且为了重定向 apache 服务器上的角度路由,我使用 .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
Run Code Online (Sandbox Code Playgroud)
有人有想法吗?谢谢!
我想发送一个 websocket,使用 express-ws 从不同的控制器发送出去,而不是通过路由,我在 server.js 中有以下代码:
var SocketController = require('./routes/ws.routes');
var app = express();
var server = require('http').createServer(app);
var expressWs = require('express-ws')(app);
app.ws('/', SocketController.socketFunction);
Run Code Online (Sandbox Code Playgroud)
SocketController 看起来像这样:
exports.socketFunction = function (ws, req) {
ws.on('message', function(msg) {
console.log(msg);
ws.send("hello");
});
}
Run Code Online (Sandbox Code Playgroud)
是否可以调用
ws.send()
来自另一个控制器的事件?我如何获得“ws”对象?
谢谢!
angular ×3
javascript ×3
express ×2
node.js ×2
android ×1
button ×1
cordova ×1
cors ×1
ios ×1
native ×1
objective-c ×1
plugins ×1
slider ×1
typescript ×1
websocket ×1