无法绑定到'valueToPass',因为它不是'app-departments'的已知属性

时间:2017-02-16 22:49:56

标签: angular input angular-components ng-modules

我对Angular2项目有疑问 我有两个组件,Departments组件和Full-Layout组件 我正在尝试使用Input()将数据从Full-Layout组件传递到Departments。

full-layout.component.ts

import {Component, OnInit} from '@angular/core';

@Component({
  selector: 'app-dashboard',
  templateUrl: './full-layout.component.html',
})
export class FullLayoutComponent implements OnInit {
  public disabled:boolean = false;
  public status:{isopen:boolean} = {isopen: false};

  constructor (

  ) { }

  ngOnInit (

  ): void { }


  dropDownItems = [
    { routerLink: '/departments',               name: 'Artshums' },
    { routerLink: '/components/social-buttons', name: 'Dentistry' },
    { routerLink: '/components/cards',          name: 'Law' },
    { routerLink: '/components/forms',          name: 'IOPPN' },
    { routerLink: '/components/modals',         name: 'LSM' },
    { routerLink: '/departments',               name: 'NMS' },
    { routerLink: '/components/tables',         name: 'Nursing' },
    { routerLink: '/components/tabs',           name: 'SSPP' },
    { routerLink: '/components/tabs',           name: 'Health' }
  ];
}

full-layout.component.html

<li class="nav-item" *ngFor="let item of dropDownItems">
    <a #clicked class="nav-link" routerLinkActive="active" [routerLink]="[item.routerLink]" (click)="onClick(clicked)">
    <i class="icon-puzzle"></i>{{item.name}}
      <app-departments [valueToPass] = "item"></app-departments>
    </a>
</li>

Departments.component.ts

import {Component, OnInit, Input} from '@angular/core';

@Component({
  selector: 'app-departments',
  templateUrl: './departments.component.html',
  inputs: ['valueToPass']
})
export class DepartmentsComponent implements OnInit {
  @Input() valueToPass;
  public _departments;
  constructor () { }
  ngOnInit() {
    console.log(this.valueToPass.name);
  }
}

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';

import { AppComponent } from './app.component';
import { DropdownModule } from 'ng2-bootstrap/dropdown';
import { TabsModule } from 'ng2-bootstrap/tabs';
import { NAV_DROPDOWN_DIRECTIVES } from './shared/nav-dropdown.directive';

import { ChartsModule } from 'ng2-charts/ng2-charts';
import { SIDEBAR_TOGGLE_DIRECTIVES } from './shared/sidebar.directive';
import { AsideToggleDirective } from './shared/aside.directive';
import { BreadcrumbsComponent } from './shared/breadcrumb.component';
import { MaterialModule } from '@angular/material';

import 'hammerjs';
// Routing Module
import { AppRoutingModule } from './app.routing';

// Layouts
import { FullLayoutComponent } from './layouts/full-layout.component';
import { SimpleLayoutComponent } from './layouts/simple-layout.component';
import {HttpModule, JsonpModule} from "@angular/http";
import {DepartmentsComponent} from "./components/departments/departments.component";
import {DepartmentsModule} from "./components/departments/departments.module";
@NgModule({
  imports: [
    BrowserModule,
    AppRoutingModule,
    DropdownModule.forRoot(),
    TabsModule.forRoot(),
    ChartsModule,
    MaterialModule.forRoot(),
    HttpModule,
    JsonpModule,
    DepartmentsModule
  ],
  declarations: [
    AppComponent,
    FullLayoutComponent,
    SimpleLayoutComponent,
    NAV_DROPDOWN_DIRECTIVES,
    BreadcrumbsComponent,
    SIDEBAR_TOGGLE_DIRECTIVES,
    AsideToggleDirective,
    DepartmentsComponent
  ],
  providers: [{
    provide: LocationStrategy,
    useClass: HashLocationStrategy
  }],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

但是我收到以下错误:

  

无法绑定到'valueToPass',因为它不是'app-departments'的已知属性。

     
      
  • 如果'app-departments'是Angular组件且输入'valueToPass',则验证它是否为此模块的一部分。
  •   
  • 如果'app-departments'是Web组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的'@ NgModule.schemas'以禁止显示此消息。 ( “cked)” &GT;
  •   

如何解决此问题?

0 个答案:

没有答案