Angular 2 : trouble in integrating ng2-select

标签 angular typescript

我面临着非常棘手的问题,我希望有人能帮助我!我已经在这里发现了很多关于同一问题的问题,但我应用了找到的解决方案,但它仍然无法正常工作!

所以我在 Angular 2 中有一个应用程序,我正在尝试集成 ng2-select,但它返回了无聊的错误:

angular2-polyfills.js:332 Error: SyntaxError: Unexpected token <

我知道每个人都在说我的 System.config 有问题,但我无法解决它!

这是我的代码!

System.config

System.config({
map: {
    'ng2-bootstrap': 'node_modules/ng2-bootstrap',
    'ng2-select': 'node_modules/ng2-select'
},
packages: {
    src: {
        format: 'register',
        defaultExtension: 'js'
    }
}
});
System.import('src/main').then(null, console.error.bind(console));

ma​​in.ts

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from "./components/app/app.component";

import 'ng2-select';
import 'ng2-bootstrap';

bootstrap(<any> AppComponent);

我的组件

import {Component} from 'angular2/core';
import {select} from "ng2-select";

@Component({
    templateUrl: 'src/views/lead/lists.view.html',
    directives: [select],
})
export class LeadListsComponent {
    team: string = "Ringo";
    teams: string[] = ["John", "Paul", "George", "Ringo"];
}

I have the files on the node_modules/ng2-angular properly I think! There is the print

但只有 TS 文件...可能是问题所在?我该怎么办?

-----更新-----

还有我的 tsconfig.json!

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "exclude": [
        "node_modules",
        "typings/main",
        "typings/main.d.ts"
    ]
}

提前致谢!

最佳答案

如果您使用的是 ng2-select,那么情况会有所不同。您必须将 systemjs 配置更改为以下内容:

systemjs.config.js

map: {
   ...,

   'ng2-select': 'node_modules/ng2-select',

   ...
},
packages: {
  ....,
  'ng2-select': {main:'ng2-select.js', defaultExtension: 'js'}
}

在你的模块下面添加导入语句

import { SelectModule } from "ng2-select/ng2-select";

然后将“SelectModule”添加到 NgModule.imports 数组。

现在在您的组件中添加以下导入语句:

import { SelectComponent } from "ng2-select/ng2-select";

关于 Angular 2 : trouble in integrating ng2-select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36274015/

相关文章:

angular - 静态解析符号时遇到错误

angular - 如何(动态)添加总行数?

TypeScript:元素隐式具有 'any' 类型,因为类型 'string' 的表达式不能用于索引类型

javascript - 在 TypeScript 中从 Promise.all 返回正确的类型

angular - 嵌套路线立即消失而不是播放:leave animation

Angular 4 - 可观察到的捕获错误

angular - 来自同一惰性路由的多个组件不起作用

mysql - 带有 Sequelize 和 Typescript 的 NodeJS

typescript - typescript 中的依赖类型 - 通过属性名称类型确定类型

javascript - 如何在 SignalR 连接上设置实际 header ?