@Component 元数据指令数组的正确替换是什么?
What is the correct replacement for the @Component metadata directives array?
在网络上的许多示例中,我在 @Component 元数据中看到带有指令数组的代码,即:
@Component({
selector: 'sprint-tasks',
inputs: ['sprintTask'],
templateUrl: './views/sprint-tasks.html',
directives: [Dragula],
providers: [SprintTaskService],
viewProviders: [DragulaService]
})
发件人:
在 Angular2 的 1.0 版本中,此数组已从元数据中删除:(https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html)
尝试使用第 3 方指令时(在本例中为 dragula
),我收到以下错误,我认为之前由 directives
数组处理过:
Can't bind to 'dragula' since it isn't a known property of 'div'
那么,我应该在哪里注入 Dragula
/DragulaDirective
(当前版本实际上似乎没有导出 Dragula
)以便解析器可以找到这个自定义指令?我已按照 Github 自述文件 (https://github.com/valor-software/ng2-dragula#setup) 的指示将 DragulaModule
导入到应用程序模块中,并且 DragulaService
是应用程序组件上的视图提供程序。
import { DragulaModule } from 'ng2-dragula/ng2-dragula';
@NgModule({
imports: [
BrowserModule,
DragulaModule
],
declarations: [
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
之后会开始工作,不需要在组件中添加。
将 dragula 模块导入应用程序模块时,这使得指令仅可用于应用程序模块中声明的组件。如果要在其上使用指令的组件在不同的模块中声明,则该模块还需要导入 dragula 模块
@NgModule({
imports: [ DragularModule ]
declarations: [ ComponentUsingDragula ],
exports: [ ComponentUsingDragula ]
})
class SomeFeatureModule {}
在网络上的许多示例中,我在 @Component 元数据中看到带有指令数组的代码,即:
@Component({
selector: 'sprint-tasks',
inputs: ['sprintTask'],
templateUrl: './views/sprint-tasks.html',
directives: [Dragula],
providers: [SprintTaskService],
viewProviders: [DragulaService]
})
发件人:
在 Angular2 的 1.0 版本中,此数组已从元数据中删除:(https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html)
尝试使用第 3 方指令时(在本例中为 dragula
),我收到以下错误,我认为之前由 directives
数组处理过:
Can't bind to 'dragula' since it isn't a known property of 'div'
那么,我应该在哪里注入 Dragula
/DragulaDirective
(当前版本实际上似乎没有导出 Dragula
)以便解析器可以找到这个自定义指令?我已按照 Github 自述文件 (https://github.com/valor-software/ng2-dragula#setup) 的指示将 DragulaModule
导入到应用程序模块中,并且 DragulaService
是应用程序组件上的视图提供程序。
import { DragulaModule } from 'ng2-dragula/ng2-dragula';
@NgModule({
imports: [
BrowserModule,
DragulaModule
],
declarations: [
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
之后会开始工作,不需要在组件中添加。
将 dragula 模块导入应用程序模块时,这使得指令仅可用于应用程序模块中声明的组件。如果要在其上使用指令的组件在不同的模块中声明,则该模块还需要导入 dragula 模块
@NgModule({
imports: [ DragularModule ]
declarations: [ ComponentUsingDragula ],
exports: [ ComponentUsingDragula ]
})
class SomeFeatureModule {}