在appcomponent中,我在html代码中使用nav组件。用户界面看起来很好。发球时没有失误。当我查看应用程序时,控制台没有错误。
但当我为我的项目运行业力时,有一个错误:
错误:
Failed: Template parse errors:
Can't bind to 'head' since it isn't a known property of 'app-widget'.
1. If 'app-widget' is an Angular component and it has 'head' input, then verify that it is part of this module.
2. If 'app-widget' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("<app-widget [ERROR ->][head]="heading"></app-widget>
规格:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HomeService } from './../../service/home.service';
import { MyFavoriteComponent } from './my-favorite.component';
describe('MyFavoriteComponent', () => {
let component: MyFavoriteComponent;
let fixture: ComponentFixture<MyFavoriteComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyFavoriteComponent ],
providers: [{provide: HomeService}]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyFavoriteComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
电话号码:
import { Component, OnInit, Input } from '@angular/core';
import { HomeService } from './../../service/home.service';
@Component({
selector: 'app-my-favorite',
templateUrl: './my-favorite.component.html',
styleUrls: ['./my-favorite.component.scss']
})
export class MyFavoriteComponent implements OnInit {
heading = '';
constructor(private homeService: HomeService) {}
ngOnInit() {
this.homeService.homeDataWidget().subscribe(response => {
this.heading = response.myfavoirte;
});
}
}
HTML格式
<app-widget [head]="heading"></app-widget>