angular - 如何在 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);
解决方案
推荐阅读
- mysql - 如何将字符串中的月份名称转换为短月份
- android - 在处理单选按钮时如何在android中使用if else阶梯
- java - 动态更改初始屏幕的背景颜色
- nginx - Nginx Plus API 后端服务器排空模式
- excel - 删除数组中每个工作簿的用户窗体和模块
- php - PHP联系表单错误发送电子邮件
- c# - 将数组重新缩放为较小的数组,保留平均值
- android - java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
- ruby-on-rails - 为什么活动存储会抛出此错误:nil:NilClass 的未定义方法“上传”,当对象不是 nil 时
- node.js - docker Cannot find module 'Sequelize'