Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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
在angular2 final中全局注册指令_Angular_Typescript_Angular2 Directives - Fatal编程技术网

在angular2 final中全局注册指令

在angular2 final中全局注册指令,angular,typescript,angular2-directives,Angular,Typescript,Angular2 Directives,我有一些自定义指令,我需要在整个应用程序中使用。如何注册在整个应用程序中使用的指令?我遇到的其他问题都过时了。我需要angular 2最终版本2.1.0的解决方案 我的main.ts如下所示 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { AppModule } from './a

我有一些自定义指令,我需要在整个应用程序中使用。如何注册在整个应用程序中使用的指令?我遇到的其他问题都过时了。我需要angular 2最终版本2.1.0的解决方案

我的
main.ts
如下所示

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

//enableProdMode(); //Uncomment for production
platformBrowserDynamic().bootstrapModule(AppModule)
    .then((success: any) => console.log('App bootstrapped'))
    .catch((err: any) => console.error(err));
import { mdinput} from './shared/mdinput.directive';


@NgModule({
    imports: [
               AppRoutingModule

    ],
    declarations: [
        AppComponent,mdinput

    ],
    providers: [DataService],
    bootstrap: [AppComponent]
})
export class AppModule {
}
我的应用程序有6个模块可以使用延迟加载

appmodule 
--contact module
--project module
--restmodules
...
当我在产品模块中注册该指令时,它运行良好。所以我在剩下的模块中使用了这个指令,我在
appmodule.ts
中注册了这个指令,如下所示

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

//enableProdMode(); //Uncomment for production
platformBrowserDynamic().bootstrapModule(AppModule)
    .then((success: any) => console.log('App bootstrapped'))
    .catch((err: any) => console.error(err));
import { mdinput} from './shared/mdinput.directive';


@NgModule({
    imports: [
               AppRoutingModule

    ],
    declarations: [
        AppComponent,mdinput

    ],
    providers: [DataService],
    bootstrap: [AppComponent]
})
export class AppModule {
}

现在这个特别的指令不起作用了。它也不会给出任何错误。

只需将其添加到功能模块中,然后将功能模块添加到要使用它的模块的导入:[…]

甚至
*ngIf
*ngFor
。。。现在需要通过将
CommonModule
BrowserModule
添加到
imports
来以这种方式添加


有关更多详细信息,请参见只需将其添加到功能模块,并将功能模块添加到要使用它的模块的导入:[…]

甚至
*ngIf
*ngFor
。。。现在需要通过将
CommonModule
BrowserModule
添加到
imports
来以这种方式添加


有关更多详细信息,请参见

首先,在单独的目录中创建指令。假设您在customDirectives目录中创建了directive:myHighlight.directive.ts。现在

import { HighlightDirective } from 'yourpath/customDirectives/myHighlight.directive';

将这些添加到app.module.ts中

现在在任何组件视图中使用此选项:

<td  myHighlight>{{user.name | capitalize}}</td>
{{user.name|capitalize}

这将如何工作。

首先,在单独的目录中创建指令。假设您在customDirectives目录中创建了directive:myHighlight.directive.ts。现在

import { HighlightDirective } from 'yourpath/customDirectives/myHighlight.directive';

将这些添加到app.module.ts中

现在在任何组件视图中使用此选项:

<td  myHighlight>{{user.name | capitalize}}</td>
{{user.name|capitalize}

这将如何工作。

只需将其添加到NgModule的声明中即可@不要让我们猜测你想要达到什么目的。编辑您的问题,并发布有关指令、模块等的所有相关信息。您可能也需要将其添加到导出中,但没有看到任何内容,这很难猜测。只需将其添加到您模块的声明中即可@不要让我们猜测你想要达到什么目的。编辑您的问题,并发布有关您的指令、模块等的所有相关信息。您可能也需要将其添加到导出中,但在没有看到任何内容的情况下,很难猜测。