小编Mel*_*lle的帖子

断言错误:传入的类型不是 ComponentType,它没有“?cmp”属性

每当应用程序运行时,我都会收到此错误,尽管在当前开发中不会给我带来问题(我认为)我想了解此错误并知道它来自何处,因为我完全迷失了,我什至无法发布相关信息代码。但我会努力的。。

所以这些是主要路线(appModule):

const routes: Routes = [
  {path:'home', component:HomeComponent, canActivate:[AuthGuardService]},
  {path:'detail/:id', component:DetailComponent},
  {path: 'register', component: RegisterComponent},
  {path:'login', component: LoginComponent},
  {path:'', redirectTo:'login', pathMatch: 'full'},
  {path:'**',  redirectTo:'login'}

];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

我有一个核心模块,其中所有组件都已注册,我正在导入RouterModule.forChild([])

@NgModule({
  declarations: [HomeComponent, DetailComponent, RegisterComponent, LoginComponent],
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    RouterModule.forChild([])
  ]
})
export class CoreModule { }
Run Code Online (Sandbox Code Playgroud)

package.json:

{
  "name": "mat-shop",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng …
Run Code Online (Sandbox Code Playgroud)

routes nested-routes angular

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

可观察:订阅组件和服务中的数据有什么区别?

订阅组件中的observable或者使用回调作为参数在服务中订阅它是否有任何显着差异?

零件

constructor(public dataService: DataService) {
     this.dataService.getData()
     .subscribe(users => {
      this.user = users;
      console.log(this.user);
     });
Run Code Online (Sandbox Code Playgroud)

服务

getData() {    
    return this.http.get(this.url)
      .map(res => res.json())
       }
Run Code Online (Sandbox Code Playgroud)

VS

零件

constructor(public dataService: DataService) {
    this.dataService.getData( callback => {
      this.user = this.dataService.user;
    });
Run Code Online (Sandbox Code Playgroud)

服务:

 getData(callback: (receiver: User) => void) {
    return this.http.get(this.url)
      .map(res => res.json())
      .subscribe(users => {
        this.user = users;
        callback(this.user);
        console.log(this.user);
      });
  }
Run Code Online (Sandbox Code Playgroud)

结果是相同的,所以除了更复杂的sintax之外,我没有太大的区别.哪个是最好的方法?

observable angular

6
推荐指数
1
解决办法
2721
查看次数

覆盖活动选项卡中的背景颜色 Angular Material

我正在尝试覆盖 Angular Material 中活动选项卡的背景颜色。我已经尝试过这篇文章,但没有成功。检查 chrome 我看到这些值:

\n\n
.mat-tab-group.mat-primary .mat-tab-label:focus, .mat-tab-group.mat-primary .mat-tab-link:focus, .mat-tab-nav-bar.mat-primary .mat-tab-label:focus, .mat-tab-nav-bar.mat-primary .mat-tab-link:focus {\n    background-color: rgba(241, 204, 206, 0.3);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

取消选中,我得到了所需的效果,但如果我将其粘贴到样式表中,则什么也不会发生。有任何想法吗?

\n\n

编辑:完整的CSS

\n\n
.mat-tab-group.mat-primary .mat-tab-label:focus, .mat-tab-group.mat-primary .mat-tab-link:focus, .mat-tab-nav-bar.mat-primary .mat-tab-label:focus, .mat-tab-nav-bar.mat-primary .mat-tab-link:focus {\n    background-color: rgba(241, 204, 206, 0.3);\n}\n<style>\xe2\x80\xa6</style>\n.mat-tab-label:focus {\n    outline: 0;\n    opacity: 1;\n}\n<style>\xe2\x80\xa6</style>\n.mat-tab-label:focus {\n    outline: 0;\n    opacity: 1;\n}\n<style>\xe2\x80\xa6</style>\n.mat-tab-label {\n    height: 48px;\n    padding: 0 24px;\n    cursor: pointer;\n    box-sizing: border-box;\n    opacity: .6;\n    min-width: 160px;\n    text-align: center;\n    display: inline-flex;\n    justify-content: center;\n    align-items: center;\n    white-space: nowrap;\n    position: relative;\n}\n<style>\xe2\x80\xa6</style>\n.mat-tab-label {\n    height: …
Run Code Online (Sandbox Code Playgroud)

css angular-material

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

角度测试:无法读取 null 的属性“nativeElement”

我是 Angular 测试的新手,目前我正在尝试测试这段代码,但我收到有关 DOM 上引发的事件的错误:

<li class="list-group-item" *ngFor="let user of users">
  <a class="test-link"[routerLink]="['/detail', user.id]">
    {{user.userName}}
  </a>
</li>
Run Code Online (Sandbox Code Playgroud)

测试文件:

beforeEach(async(() => {
  TestBed.configureTestingModule({
    declarations: [AdminComponent, UserDetailComponent],
    imports: [HttpClientModule,RouterTestingModule.withRoutes([
      {path:'detail/:id',
        component: UserDetailComponent}],
    )],
    providers: [UserService, AuthService]
  })
    .compileComponents();
}));

beforeEach(() => {
  router = TestBed.get(Router);
  location = TestBed.get(Location);

  fixture = TestBed.createComponent(AdminComponent);
  debugElement = fixture.debugElement;
  component = fixture.componentInstance;
  fixture.detectChanges();

});

it('test demands redirection', fakeAsync(() => {

  debugElement
    .query(By.css('.test-link'))
    .nativeElement.click();

  tick();

  expect(location.path()).toBe('/detail/testing/1');

}));
Run Code Online (Sandbox Code Playgroud)

为什么本机元素上的点击事件为空?

integration-testing karma-runner angular angular-routerlink

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