我正在使用Angular 2 CLI,并使用.创建了组件"MyComponent" ng generate component MyComponent
.据我所知,我必须将组件添加到@Component
装饰器的指令键值对,但此时打字稿编译失败,说:
ERROR in [default] /Users/Philip/Desktop/Angular2/src/app/app.component.ts:8:2
Argument of type '{ selector: string; template: any; styles: any[]; directives: typeof MyComponentComponent[]; }' is not assignable to parameter of type 'Component'.
Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序代码:
import { Component } from '@angular/core';
import { MyComponentComponent } from './my-component/my-component.component'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
directives: [MyComponentComponent],
})
export class AppComponent {
title = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有nodemon的babel-node进行热重新加载.我基本上跟着这个回购.
我的dev
脚本package.json
看起来像这样:
"dev": "nodemon app.js --exec babel-node --presets env"
Run Code Online (Sandbox Code Playgroud)
我的.babelrc
:
{
"presets": ["env"]
}
Run Code Online (Sandbox Code Playgroud)
尽管扩展运算符被列为env预设支持,但在使用此设置时,我得到了一个
SyntaxError:意外的令牌
我正在尝试实现与 flutter 频道上一周视频小部件中显示的效果非常相似的效果:https : //www.youtube.com/watch?v= dYRs7Q1vfYI#t =1m20s
在右侧,您会看到所需的结果,在左侧,您会看到我的应用程序中当前正在发生的事情。
我一直在使用的代码与示例视频中的代码非常相似,使用堆栈将背景滤镜放置在我的图像上。圆形图像及其上的模糊位于一个小部件中,该小部件将放置在另一个堆栈中(与底部的文本一起)。由于我只应用了图像的一小部分过滤器,我不明白为什么整个应用程序都是模糊的。这是图像小部件的代码:
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size.width - 75;
return Container(
height: size,
width: size,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Image(imageUri: "...", size: size - 30), // this is just a container with the image
Positioned(
top: 100,
left: 100,
bottom: 100,
right: 100,
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 5,
sigmaY: 5,
),
child: Container(
color: Color(0x66FF0000),
),
),
)
],
),
);
}
}
Run Code Online (Sandbox Code Playgroud) 我在High Sierra上使用Xcode版本9.0.1(9A1004).运行时,tns doctor
我收到以下警告:
WARNING: Xcode is not installed or is not configured properly.
You will not be able to build your projects for iOS or run them in the iOS Simulator.
To be able to build for iOS and run apps in the native emulator, verify that you have installed Xcode.
Run Code Online (Sandbox Code Playgroud)
如果我运行安装脚本,我得到:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Xcode is not installed or not configured properly. Download, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个实用程序 npm 包。在我的src
目录中,我有一堆声明多个接口/类型的打字稿文件。例如在src/value-updatable.ts
我有:
export interface UnaryValueUpdatable<T> {
value: T;
onChange: (value: T) => void;
}
Run Code Online (Sandbox Code Playgroud)
我将整个源代码编译为dist/
,因为它是一个实用程序包,没有入口或主文件,我只想在其他项目中使用这些类型。我什至不确定是否需要编译,但问题仍然相同。当我在不同的项目中安装包时,我必须从dist/
orsrc/
而不是从包名本身导入。
例如:
import {UnaryValueUpdatable} from "my-utility-package/dist/UnaryValueUpdatable"
我必须如何配置我的包以公开这样的“漂亮”路径:import {whatever} from "my-utility-package/whatever"
?
包.json:
{
"name": "my-utility-package",
"version": "1.0.0",
"files": [
"dist/**/*"
],
"scripts": {
"build": "tsc"
},
"license": "MIT",
"dependencies": {
"typescript": "^3.6.4"
}
}
Run Code Online (Sandbox Code Playgroud)
配置:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true, …
Run Code Online (Sandbox Code Playgroud) 以下代码应该简单地禁止任何按键并将按下的键添加到div中.这在桌面上工作正常,但在移动设备(safari和chrome)上event.key
是未定义的.
<html>
<head></head>
<body>
<input />
<div id="#test"></div>
<script>
var str = '';
var el = document.getElementById('#test');
document.addEventListener('keypress', function(event) {
str += event.key;
event.preventDefault();
el.innerHTML = str;
})
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
event.keyCode
并且event.keyIdentifier
都可用但是将它们转换为字符串会在不同的键盘布局和语言上给出不必要的结果,特别是对于特殊字符.
无论如何直接获得密钥的价值?
这是一个代码示例,以防万一:https://codepen.io/anon/pen/pryYyQ
我正在用框阴影构建自己的类似于材料的卡片。我想将其中几个组合成一个PageView
,以便我可以在卡之间滑动-每个卡Card
应填满整个屏幕宽度。该卡具有BoxShadow
作为装饰,插入然而,当Card
进入PageView
(或任何其它包装插件)时,BoxShadow
因为它是由限幅就会消失PageView
的边界框。
可以通过将Card
换成a 来解决此问题Padding
,但这不是我想要的,因为我更喜欢由最外面的小部件给整个视图的所有子小部件提供填充-因此,如果我的填充发生更改,我就不会更改每个小部件。
这是我的Card
代码的样子:
class Card extends StatelessWidget {
final Widget child;
final EdgeInsetsGeometry padding;
Card({@required this.child, this.padding});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: Colors.white, boxShadow: <BoxShadow>[
BoxShadow(color: Color.fromRGBO(0, 0, 0, 0.1), blurRadius: 14.0),
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(0, 2),
blurRadius: 2.0)
]),
child: Padding(
padding: padding ?? EdgeInsets.all(20),
child: this.child,
),
);
} …
Run Code Online (Sandbox Code Playgroud) 我在使用联系服务添加联系人时收到错误。
Contact newContact = new Contact();
newContact.givenName ="Ajay";
newContact.familyName ="abc";
newContact.phones = [Item(label: "mobile",value: "9998887771")];
await ContactsService.addContact(newContact);
Run Code Online (Sandbox Code Playgroud) 我有以下功能:
const infer = (...params: string[]): Record<string, string> => {
const obj: Record<string, string> = {};
// Put all params as keys with a random value to obj
// [...]
return obj;
}
Run Code Online (Sandbox Code Playgroud)
这个函数将接受 n 个字符串并返回一个包含这些字符串作为键的对象,并带有随机值。
所以infer("abc", "def")
可能会回来{"abc": "1337", "def":"1338"}
。
有没有办法推断返回类型以从此函数获得完整的类型安全?该函数的代码保证每个键都将出现在返回的对象中,并且每个值都是一个字符串。
event.preventDefault() 不适用于 Chrome Android 操作系统。而同样的动作正在 chrome IOS 上工作。我什至使用了 event.stopPropagation()、event.stopImmediatePropagation()。
HTML:
<input class="otherAmount" type="text"id="pVal" name="pVal" onkeydown="validatePaymentToTwoDecimal(this,event);"/>
Run Code Online (Sandbox Code Playgroud)
Java脚本:
function validatePaymentToTwoDecimal(el, evt) {
if(!$.isNumeric(evt.key)|| evt.key=="."){
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
return false;
} else {
return true;
}
}
Run Code Online (Sandbox Code Playgroud) flutter ×3
javascript ×3
typescript ×3
angular ×1
atom-editor ×1
babel ×1
babel-node ×1
keylistener ×1
nativescript ×1
node.js ×1
npm ×1
package.json ×1
tsconfig ×1
xcode ×1