小编Kim*_*ern的帖子

什么是Angular Material 2组件中的`cdk`

在角度材质源中的多个位置,有元素/ css类cdk作为其前缀.

有谁知道cdk角度材料上下文中的缩写?

angular-material2 angular-cdk

104
推荐指数
3
解决办法
3万
查看次数

Angular 2 Karma Test'component-name'不是已知元素

在AppComponent中,我在HTML代码中使用nav组件.用户界面看起来很好.做服务时没有错误.当我查看应用程序时,控制台中没有错误.

但是当我为我的项目运行Karma时,出现了一个错误:

Failed: Template parse errors: 
'app-nav' is not a known element:
1. If 'app-nav' is an Angular component, then verify that it is part of this module.
2. If 'app-nav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
Run Code Online (Sandbox Code Playgroud)

在我的app.module.ts中:

有:

import { NavComponent } from './nav/nav.component';
Run Code Online (Sandbox Code Playgroud)

它也在NgModule的声明部分

@NgModule({
  declarations: [
    AppComponent,
    CafeComponent,
    ModalComponent,
    NavComponent,
    NewsFeedComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    JsonpModule,
    ModalModule.forRoot(),
    ModalModule,
    NgbModule.forRoot(),
    BootstrapModalModule,
    AppRoutingModule
  ], …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript karma-jasmine angular

81
推荐指数
2
解决办法
4万
查看次数

如何在角形材料中水平对齐单选按钮?

我期待一个内置指令或标签,但可能不是根据他们的文档.

这是一个例子.

<div class="radioButtondemoBasicUsage" ng-app="MyApp">
<form ng-submit="submit()" ng-controller="AppCtrl">
<p>Selected Value: <span class="radioValue">{{ data.group1 }}</span> </p>

<md-radio-group ng-model="data.group1">

  <md-radio-button value="Apple" class="md-primary">Apple</md-radio-button>
  <md-radio-button value="Banana"> Banana </md-radio-button>
  <md-radio-button value="Mango">Mango</md-radio-button>

</md-radio-group>
Run Code Online (Sandbox Code Playgroud)

css angularjs angularjs-material

44
推荐指数
2
解决办法
4万
查看次数

println!借用或拥有变量?

我对借贷和所有权感到困惑.在Rust 文档中有关引用和借用的内容

let mut x = 5;
{
    let y = &mut x;
    *y += 1;
}
println!("{}", x);
Run Code Online (Sandbox Code Playgroud)

他们说

println!可以借x.

我很困惑.如果println!借入x,为什么它通过x&x

我尝试在下面运行此代码

fn main() {
    let mut x = 5;
    {
        let y = &mut x;
        *y += 1;
    }
    println!("{}", &x);
}
Run Code Online (Sandbox Code Playgroud)

除了传递&x给代码之外,这段代码与上面的代码相同println!.它将'6'打印到控制台,这是正确的,与第一个代码的结果相同.

ownership rust

39
推荐指数
1
解决办法
2219
查看次数

Angular2 zone.run()vs ChangeDetectorRef.detectChanges()

假设我function noificationHandler()在我的service.ts中有一个超出angular的上下文. noificationHandler()由第三方调用并noificationHandler()基本上使用数组并将数组发送到已订阅其服务的组件.

service.ts

    public mySubject: Subject<any> = new Subject();
    public myObservable = this.mySubject.asObservable();

    constructor() {
       this.registry.subscribe("notification.msg",this.noificationHandler.bind(this));
    }

    noificationHandler(data) {
       this.publishUpdate(data)
    }

    publishUpdate(data) {
       this.mySubject.next(data);
    }
Run Code Online (Sandbox Code Playgroud)

component.ts

constructor(private service: myService) {
    this.service.myObservable.subscribe(list => {
        this.list = list;
    });
}
Run Code Online (Sandbox Code Playgroud)

此时^^^模板未使用新数据更新

由于"notification.msg"它位于角度区域之外,因此("notification.msg")在调用此事件时不会运行角度变化检测.

现在有两种方法可以调用变化检测.

1)通过包装noificationHandler()angular的zone.run()的内部

 this.registry.subscribe("a2mevent.notification.msg", this.ngZone.run(() => this.noificationHandler.bind(this)));
Run Code Online (Sandbox Code Playgroud)

2)通过单独要求组件检测变化

constructor(private service: myService, private ref: ChangeDetectorRef) {
    this.service.myObservable.subscribe(list => {
        this.list = list;
        this.ref.detectChanges(); // <==== manually invoking change detection
    }); …
Run Code Online (Sandbox Code Playgroud)

javascript angular2-changedetection angular

26
推荐指数
2
解决办法
9555
查看次数

如何获得角度2的当前路线自定义数据?

我设置的路线如下

const appRoutes: Routes = [
  {
    path: 'login',
    component: LoginComponent,
    data: {
      title: 'Login TTX'
    }
  },
  {
    path: 'list',
    component: ListingComponent,
    data: {
      title: ' TTX Home Page',
      module:'list'
    }
  },
  {
    path: '',
    redirectTo: '/login',
    pathMatch: 'full'
  },
];
Run Code Online (Sandbox Code Playgroud)

现在,当我来'/list' 路线然后'listing.component.ts'我写下面的代码

export class ListingComponent {

  public constructor(private router:Router) {
      //here how i can get **data** of **list** routes

  }
}
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

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

如何将新的FormGroup或FormControl附加到表单

form在Angular中创建了以下内容FormBuilder:

constructor(private fb: FormBuilder) {
    this.myForm = fb.group({
        'name': ['', [Validators.required],
        'surname': ['', [Validators.required],
        'email': ['', [validateEmail]],
        'address': fb.group({
            'street': [''],
            'housenumber': [''],
            'postcode': ['']
        }, { validator: fullAddressValidator })
    });
}
Run Code Online (Sandbox Code Playgroud)

是否存在以编程方式附加新字段(如FormControlnew或new)的FormGroup方法myForm

我的意思是,如果我想按需或在某些条件下添加新字段,如何将项目添加到第一次创建的同一表单中constructor

forms angular2-forms angular2-formbuilder angular

21
推荐指数
3
解决办法
4万
查看次数

Angular CDK:如何在ComponentPortal中设置输入

我想从材料CDK 使用新的Portal在表单的多个部分中注入动态内容.

我有一个复杂的表单结构,目标是有一个表单,指定子组件可以(或不)注入模板的多个位置.

也许CDK门户网站不是最好的解决方案?

我试了一下,但我确定这不是做的事情:https: //stackblitz.com/edit/angular-yuz1kg

我也尝试过,new ComponentPortal(MyPortalComponent)但我们如何设置输入呢?通常是这样的componentRef.component.instance.myInput

angular-material2 angular angular-cdk

21
推荐指数
6
解决办法
8363
查看次数

如何在 Nestjs 中刷新令牌

import { ExtractJwt, Strategy } from 'passport-jwt';
import { AuthService } from './auth.service';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtPayload } from './model/jwt-payload.model';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor(private readonly authService: AuthService) {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      secretOrKey: 'secretKey',
    });
  }

  async validate(payload: JwtPayload) {
    const user = await this.authService.validateUser(payload);
    if (!user) {
      throw new UnauthorizedException();
    }
    return true;
  }
}
Run Code Online (Sandbox Code Playgroud)

令牌是从请求中提取的PassportStrategy。我不知道如何在令牌过期或无效时捕获错误。我的目的是如果因为令牌过期而出现错误,我需要刷新令牌。否则做别的事情。

javascript node.js typescript passport.js nestjs

21
推荐指数
2
解决办法
2万
查看次数

从另一个模块注入nestjs服务

我有一个PlayersModule和一个ItemsModule.

我想用ItemsServicePlayersService.

当我通过注射添加它时:

import { Injectable } from '@nestjs/common';
import { InjectModel } from 'nestjs-typegoose';
import { ModelType, Ref } from 'typegoose';
import { Player } from './player.model';
import { Item } from '../items/item.model';
import { ItemsService } from '../items/items.service';

@Injectable()
export class PlayersService {
    constructor(
        @InjectModel(Player) private readonly playerModel: ModelType<Player>,
        private readonly itemsService: ItemsService){}
Run Code Online (Sandbox Code Playgroud)

我得到这个嵌套错误:

[Nest] 11592 - 2018-8-13 11:42:17 [ExceptionHandler] Nest无法解析PlayersService(+ ,?)的依赖关系.请确保索引[1]的参数在当前上下文中可用.

两个模块都导入了app.module.ts.这两项服务都在他们的模块中单独工作.

javascript node.js nestjs

20
推荐指数
4
解决办法
8423
查看次数