Angular - 为什么ViewRef不能注入组件

时间:2018-03-08 03:55:38

标签: angular

我正在尝试获取ViewRef表单组件,这是代码:

import { Component,ViewRef } from '@angular/core'
@Component({
   selector: 'test-com',
   template: ` <div>just test</div>`
})
export class TestComponent{
   constructor(private _viewRef: ViewRef){}
}

当我运行它时,错误如下:

  

ViewRef没有提供商

但是当我使用ViewContainerRef时,它很好。

有人告诉我原因! Angular如何告诉哪个服务可以注入,哪个不是?

1 个答案:

答案 0 :(得分:0)

您是否在应用模块中向提供者数组中添加了ViewRef?我认为这就是问题所在。

相关问题