我将@Input添加到了角2指令中,得到了一个错误,使我相信我没有导入包含@Input元数据的角2模块。
zone.js:1263 GET http://localhost:8880/vendor/@angular/core/bundles/core.umd.js/src/metadata/directives.js 404 (Not Found)这一点的证明是,当我删除@Input元数据时,应用程序不会生成任何错误。
在我使用@Input元数据的模块中,我从IDEA (IDEA 2016.2)中导入了{Input} (IDEA 2016.2),自动为我添加了引用。
所以我需要通过@NgModule导入合适的角度2模块,但是我不知道如何确定它的名称或位置。
下面是我的ApplicationModule (引导)模块定义:
import {NgModule} from '@angular/core';
import {BrowserModule, Title} from '@angular/platform-browser';
import {RouterModule} from '@angular/router';
import {UtilityModule} from '../utility/module';
import {I18NModule} from '../i18n/module';
import {FrameworkModule} from '../framework/module';
import {ApplicationComponent} from './application.component';
import {applicationRouting, applicationRoutingProviders} from './application.routing';
import {SandboxComponent} from './sandbox.screen/sandbox.component';
import {SpreadsheetComponent} from './spreadsheet.screen/spreadsheet.component';
@NgModule({
imports: [BrowserModule, RouterModule, UtilityModule, I18NModule, applicationRouting, FrameworkModule],
providers: [Title, applicationRoutingProviders],
declarations: [ApplicationComponent, SandboxComponent, SpreadsheetComponent],
bootstrap: [ApplicationComponent]
})
export class ApplicationModule {}这是我的FrameworkModule,我正在尝试使用@Input
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {TUT_FRAMEWORK_DIRECTIVES} from './directives/index';
import {TUT_FRAMEWORK_COMPONENTS} from './components/index';
@NgModule({
imports: [BrowserModule],
providers: [],
declarations: [TUT_FRAMEWORK_DIRECTIVES, TUT_FRAMEWORK_COMPONENTS],
exports: [TUT_FRAMEWORK_DIRECTIVES, TUT_FRAMEWORK_COMPONENTS]
})
export class FrameworkModule {}想必我需要将一个角2模块导入到其中一个文件中,以提供@Input的实现。
一般而言,提供了角2模块的列表在哪里?我如何确定哪些模块对应于角2的哪些特征?
进一步研究
来自From网站(API文档):
https://angular.io/docs/ts/latest/api/
@角/芯
Input
https://angular.io/docs/ts/latest/api/core/index/Input-interface.html
从@角/核心/索引导出,定义为@角/核心/src/元数据/指向。
我不知道如何解释上述任何有关我需要包括在引导模块定义中的信息.(可能是我撞错了树)
发布于 2016-09-29 06:56:05
要在组件中使用@Input(),必须从核心包导入Input,如下所示-
import { Input } from '@angular/core';参考资料:https://angular.io/docs/ts/latest/cookbook/component-communication.html
看看这个有用吗。
发布于 2016-09-29 15:26:07
我发现了我的问题:
在我的指令中,我的IDE用它的完整路径帮助导入了Input:
import {Input} from '@angular/core/src/metadata/directives';Range2的发行版本提供了包,在我的system.config.js文件中,我引用了这些包,如下面的代码段所示:
System.config(
{
paths: {
// paths serve as alias
'npm:': 'vendor/'
},
// tell the SystemJS loader where to look for packages and components
map: {
'application': '.',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
...由于我的导入包含到Input的扩展路径,所以系统加载程序将其附加到System.config map:条目中的引用中.导致加载角2核心模块(404)的路径错误
zone.js:1263 GET http://localhost:8880/vendor/@angular/core/bundles/core.umd.js/src/metadata/directives.js 404 (Not Found)注意附加到core.umd.js包引用的core.umd.js..。
为了解决我的问题,我所需要做的就是引用core模块,而不是在typings文件中声明export for Input (如下所示):
import {Input} from '@angular/core';https://stackoverflow.com/questions/39758623
复制相似问题