首页 > 解决方案 > 如何在 Angular 应用程序中添加模块而不会在控制台中出错?

问题描述

我在向我的 Angular 应用程序添加新模块时遇到问题。我需要将 ng2-search-filter 添加到我的应用程序中,但我在控制台中收到此错误并且我的应用程序无法运行

我按原样添加了所有内容,这是我的文件和文件结构。注意:我正在我的 .net Web 应用程序中创建我的 Angular 应用程序,并且我正在通过 package.json 添加新模块。

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';

import { APP_BASE_HREF } from '@angular/common';
import { routing } from './app.routing';

import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';

import { LoginService } from './service/login.service';
import { SearchUserComponent } from './search-user/search-user.component';

import { RegisterComponent } from './register/register.component';
import { RegisterService } from './service/register.service';
import { CategoryManagementService } from './service/category-management';
import { LanguageManagementService } from './service/language-management';

import { SearchBooksService } from './service/search-books.service';
import { SearchBooksComponent } from './search-books/search-books.component';

import { Ng2SearchPipeModule } from "ng2-search-filter";


@NgModule({
    imports: [BrowserModule, HttpModule, FormsModule, routing, Ng2SearchPipeModule],
    declarations: [AppComponent, RegisterComponent, LoginComponent, SearchUserComponent, SearchBooksComponent],
    providers: [{ provide: APP_BASE_HREF, useValue: '/' }, RegisterService, LoginService, LanguageManagementService, CategoryManagementService, SearchBooksService],
    bootstrap: [AppComponent]
})
export class AppModule { }

systemjs.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',


      // other libraries
      'rxjs':                      'npm:rxjs',
        'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'ng2-search-filter': 'node_modules/ng2-search-filter'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js',
        main:'main.js'

      },
      rxjs: {
        defaultExtension: 'js'
        },

      'ng2-search-filter': { main: 'dist/index.js' }
    }
  });
})(this);

node_modules/ng2-搜索过滤器

我进入控制台时出错

标签: angular

解决方案


推荐阅读