在角度中,我将数据与主机侦听器绑定,如下面的代码
@HostListener('window:keyup', ['$event'])
onKeyUp(event: KeyboardEvent) {
if (event.keyCode === 13) {
this.onEnterClicked(event);
}
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我想13
用Keycode.ENTER替换。但是没有可用的类来保存 Angular 和 JavaScript 中每个键的常量。
那么我还缺什么课吗?如果不是,那么为什么 javascript 或 Angular 没有在一处定义常量?
我想要的是,如果网络不可用,并且用户尝试导航到下一页,那么ConnectionLost
Component就在那里.
但是,如果没有网络,用户不采取任何行动意味着不导航到第二页.那么不应该有一个连接丢失的页面.用户应该留在当前页面上.
为此,我已经实现了canActivate guard作为以下代码:
@Injectable({
providedIn: 'root'
})
export class NetworkGuard implements CanActivate {
constructor(private router: Router, private network: NetworkService) {
}
canActivate(next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (window.navigator.onLine) {
return true;
} else {
if (!this.isConnectionLostComponent()) {
this.router.navigate(['/connection-lost'], {skipLocationChange: true});
}
return false;
}
}
private isConnectionLostComponent() {
// check whether connection lost component is added on not
return this.network.isActive;
}
}
Run Code Online (Sandbox Code Playgroud)
除了一个条件外它工作正常.也就是说,如果我从浏览器单击后退或前进,它的更新URL connection-lost
到地址栏 …
我必须将 javascript 的一些字段投影到新对象。
例如我有一个下面的对象
var obj = { fn : 'Abc',
ln : 'Xyz',
id : 123,
nt : 'Note',
sl : 50000}
Run Code Online (Sandbox Code Playgroud)
我想要包含的新对象 fn and id
var projectedObj = { fn : 'Abc', id : 123 }
Run Code Online (Sandbox Code Playgroud)
基于投影
var projection = { fn : 1, id : 1 }
Run Code Online (Sandbox Code Playgroud)
像这样的东西
var projectedObj = project(obj, projection);
Run Code Online (Sandbox Code Playgroud)
那么什么是最好的方法或优化的方法来做到这一点。
如何限制组件在背压时加载.实际上我有三个组件A(正常组件),B(LoginComponent)和C(Otp验证组件).我在某个按钮点击时从A路由到组件B,从B到C路由到组件B以验证用户.现在在对组件C进行验证之后,我想回到组件'A',并希望从历史记录中删除组件'B'和'C',以便在从浏览器返回时不加载'B'(LoginComponent)和'C'再次.那怎么能在angularjs 2中做到这一点.
typescript angular2-routing angular-component-router angular-components angular
在许多 ReactJs 项目中,其中之一抛出以下错误:
Error: Material-UI: unsupported non-unitless line height with grid
alignment. Use unitless line heights instead.
Run Code Online (Sandbox Code Playgroud)
在定义 lineHeight 时px
,下面是我的代码:
const breakpoints = createBreakpoints({});
let theme = createMuiTheme({
typography: {
allVariants: {
fontFamily
},
h1: {
fontWeight: 600,
fontSize: 26,
lineHeight: '32px',
[breakpoints.down("sm")]: {
fontSize: 18,
lineHeight: '26px',
}
},
h2: {
fontWeight: 600,
fontSize: 20,
lineHeight: 28 / 20
},
h3: {
fontWeight: 600,
fontSize: 16,
lineHeight: '22px',
[breakpoints.down("sm")]: {
fontSize: 14,
lineHeight: '20px',
}
}
} …
Run Code Online (Sandbox Code Playgroud) 我正在使用vim
editor 并且想要编辑vim editor提供的一些默认选项。
即N+G(5G) 移动到第 n 行,但我希望 N+Enter 移动到第 n 行
同样地:
^想改成s
$想改成e
等等
angular ×3
javascript ×3
command-line ×1
css ×1
ecmascript-5 ×1
ecmascript-6 ×1
guard ×1
linux ×1
material-ui ×1
optimization ×1
reactjs ×1
shell ×1
typescript ×1
unix ×1
vim ×1
web ×1