Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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 如何让组件投入使用_Angular - Fatal编程技术网

Angular 如何让组件投入使用

Angular 如何让组件投入使用,angular,Angular,谁能告诉我如何让组件投入使用? 例子: 组件A中(可以是任何组件) 在职 call(){ how to get component instance or viewContainerRef? } 一种方法是让组件实现接口。然后可以将参数传递给服务方法。他们认为输入参数的类型应该输入到您的接口中 //component example class MyComponent implements IComponent { someCommonMethodName(){} // meth

谁能告诉我如何让组件投入使用? 例子: 组件A中(可以是任何组件)

在职

call(){
     how to get component instance or viewContainerRef?
}

一种方法是让组件实现接口。然后可以将参数传递给服务方法。他们认为输入参数的类型应该输入到您的接口中

//component example
class MyComponent implements IComponent {
  someCommonMethodName(){} // method required by interface
}

//service method
doWhatever(component: IComponent) {
  component.someCommonMethodName(); // you can trust that this method exists
}

为什么不把它当作一个论点来通过呢?
//component example
class MyComponent implements IComponent {
  someCommonMethodName(){} // method required by interface
}

//service method
doWhatever(component: IComponent) {
  component.someCommonMethodName(); // you can trust that this method exists
}