小编Ali*_*eño的帖子

Angular 2+ window.onfocus和windows.onblur

因此,我需要在Angular 2或4中管理我的应用程序的浏览器选项卡是否关注.有没有办法使用window.onfocuswindow.onblur

非常感谢

javascript typescript angular

12
推荐指数
2
解决办法
5357
查看次数

Angular 4延迟加载和路由不起作用

我有一个模块与我的应用程序的路线.其中一条路线是延迟加载模块.

问题是这个延迟加载模块内部有子组件的路由.但是在我的路由器配置上这条路线没有出现......所以当我打电话给懒人模块时,我的屏幕上没有显示任何内容.

这是我的路由器配置(主模块):

export const MODULE_ROUTES: Route[] =[
    { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
    { path: 'dashboard', component: HomeComponent, canActivate: [AuthGuard] },
    { path: 'calendar', loadChildren: 'app/dashboard/calendar/calendar-module.module#CalendarModuleModule',canActivate: [AuthGuard]}, 
    { path: '**', component: NoPageFoundComponent, pathMatch: 'full' }
]
.
.
.


@NgModule({
    imports: [
        RouterModule.forChild(MODULE_ROUTES)
.
.
.
Run Code Online (Sandbox Code Playgroud)

在我的懒惰模块上:

export const MODULE_CALENDAR_ROUTES: Route[] = [
    {
        path: 'calendar', component: CalendarComponent, canActivateChild: [AuthGuard, CalendarGuard],
        children: [
            {
                path: '', component: MainCalendarComponent, canActivateChild: [AuthGuard, CalendarGuard]
            },
            {

                path: 'user', component: EditEventComponent, …
Run Code Online (Sandbox Code Playgroud)

lazy-loading angular-module angular2-routing angular

5
推荐指数
1
解决办法
1万
查看次数

没有AuthHttp的提供者!在angular2-jwt上

我是Angular 2的新手,我想在我的项目中使用JWT.所以我按照指示准确地从angular2-jwt的官方页面使用基本配置给出.我用以下代码创建了一个名为auth.module.ts的文件:

import { NgModule } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';

function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig(), http, options);
}

@NgModule({
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, RequestOptions]
    }
  ]
})
export class AuthModule {}
Run Code Online (Sandbox Code Playgroud)

下一步是发送经过身份验证的请求.我使用一个组件,我放置一个按钮,调用一个函数来执行页面上建议的代码:

文件:calendario.components.ts

import {Component, OnInit,trigger,state,style,transition,animate,keyframes, group} from '@angular/core';
import initDemo = require('../../../assets/js/charts.js');
import initNotify = require('../../../assets/js/notify.js');
import { AuthHttp } from 'angular2-jwt';

declare var $:any; …
Run Code Online (Sandbox Code Playgroud)

authentication jwt angular2-jwt angular

3
推荐指数
1
解决办法
1912
查看次数