Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 为什么会出现有角度的Web包stater don';提供程序中的t状态AppState,;然而,国家的标题,这也是服务_Angular_Angular2 Providers - Fatal编程技术网

Angular 为什么会出现有角度的Web包stater don';提供程序中的t状态AppState,;然而,国家的标题,这也是服务

Angular 为什么会出现有角度的Web包stater don';提供程序中的t状态AppState,;然而,国家的标题,这也是服务,angular,angular2-providers,Angular,Angular2 Providers,代码的地址是 因为他们是在模块级提供的 Angulars DI是分层的。当一个组件有依赖项时,DI会查看组件提供程序,它的父组件提供程序一直到AppComponent,然后继续查看模块级提供的提供程序,在那里它会找到AppState,感谢您解决了我的问题! import { AppState } from '../app.service'; import { Title } from './title'; import { XLargeDirective } from './x-large'

代码的地址是


因为他们是在模块级提供的


Angulars DI是分层的。当一个组件有依赖项时,DI会查看组件提供程序,它的父组件提供程序一直到
AppComponent
,然后继续查看模块级提供的提供程序,在那里它会找到
AppState

,感谢您解决了我的问题!
import { AppState } from '../app.service';
import { Title } from './title';
import { XLargeDirective } from './x-large';

@Component({

  selector: 'home',

  providers: [
    Title
  ],

  styleUrls: [ './home.component.css' ],

  templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {

  public localState = { value: '' };

  constructor(
    public appState: AppState,
    public title: Title
  ) {}
.....