如何使指令成为全局指令,以便在页面上任何不完全由angular 2控制的位置使用

如何使指令成为全局指令,以便在页面上任何不完全由angular 2控制的位置使用,angular,angular2-template,angular2-directives,Angular,Angular2 Template,Angular2 Directives,有没有办法使指令全球化?我需要从页面上任何不完全受angular 2控制的位置添加一个示例: 我想创建angular 2创建的(日期选择器、网格或图像列表…等等),然后在其他类似于此类HTML的框架创建的页面的任何位置使用此组件: <body> <label>birth of date</label> <input type= "text" id='dob' angular2datetimepicker > <lab

有没有办法使指令全球化?我需要从页面上任何不完全受angular 2控制的位置添加一个示例: 我想创建angular 2创建的(日期选择器、网格或图像列表…等等),然后在其他类似于此类HTML的框架创建的页面的任何位置使用此组件:

<body>
    <label>birth of date</label>
    <input type= "text" id='dob' angular2datetimepicker  >
    <label>Join Date</label>
    <input type= "text" id= 'jod' angular2datetimepicker  > 
</body>

出生日期
加入日期

其中,
angular2datetimepicker
是在angular 2中创建的组件或自定义指令,但在angular 2范围之外使用。

您可以
引导
使用:

引导应用程序时可以提供的令牌,使应用程序的每个组件中都有可用的指令数组

import {PLATFORM_DIRECTIVES} from 'angular2/core';
import {OtherDirective} from './myDirectives';
@Component({
  selector: 'my-component',
  template: `
    <!-- can use other directive even though the component does not list it in `directives` -->
    <other-directive></other-directive>
  `
})
export class MyComponent {
  ...
}
bootstrap(MyComponent, [provide(PLATFORM_DIRECTIVES, {useValue: [OtherDirective], multi:true})]);

请参阅。

您可以
引导
使用:

引导应用程序时可以提供的令牌,使应用程序的每个组件中都有可用的指令数组

import {PLATFORM_DIRECTIVES} from 'angular2/core';
import {OtherDirective} from './myDirectives';
@Component({
  selector: 'my-component',
  template: `
    <!-- can use other directive even though the component does not list it in `directives` -->
    <other-directive></other-directive>
  `
})
export class MyComponent {
  ...
}
bootstrap(MyComponent, [provide(PLATFORM_DIRECTIVES, {useValue: [OtherDirective], multi:true})]);

请参阅。

谢谢@acdcjunior,但在我的情况下,该指令应该添加到主页-index.html-因为有其他框架主要控制此页面,并且包含其他元素,我无法将其移动到componenent.html。还有什么框架?如果您有这些要求,也许您可以将控件的对象添加到
窗口
对象,然后在
bootstrap()
ing时引用它。为此,我收到一条警告:清理不安全样式值函数(){return(this.layout=='column')?'column':'row';}(请参阅)。Angular 2.0.0对此有更新吗?谢谢@acdcjunior,但在我的情况下,指令应该添加到主页-index.html-因为有其他框架主要控制此页面,并且包含其他元素,我无法将其移动到componenent.html。还有什么框架?如果您有这些要求,也许您可以将控件的对象添加到
窗口
对象,然后在
bootstrap()
ing时引用它。为此,我收到一条警告:清理不安全样式值函数(){return(this.layout=='column')?'column':'row';}(请参阅)。Angular 2.0.0有更新吗?