我正面临着非常棘手的问题,我希望任何人都能帮助我!我在这里已经发现了很多关于同一个问题的问题,但我应用了找到的解决方案,但它仍然不起作用!
因此,我在角2中有一个应用程序,我正在尝试集成ng2-select,它正在返回无聊的错误:
Angular2-polyadds.js:332错误: SyntaxError:意外令牌<
我知道每个人都说这是我的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));main.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"];
}但只有TS文件..。这可能是问题所在吗?我该怎么办?
-----UPDATE-----
这也是我的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"
]
}提前感谢!
发布于 2016-03-29 05:03:18
我认为您的问题是,当您为选择您的名字做一个导入时是错误的:
在MyComponent中,您应该这样做:
import {Select} from "ng2-select";其中select中的S是大写的。通常当你得到一个:
Angular2-polyadds.js:332错误: SyntaxError:意外令牌<
这意味着一个404错误,您的模块没有正确加载。但NG2-选择出口Select而不是select。
你可能还得做:
import {Select} from "ng2-select/select";我不能100%确定npm是如何将它加载到节点模块目录中的,因为我没有使用它。
发布于 2016-12-27 23:01:53
如果您正在使用ng2-select,那么事情已经发生了一些变化。您必须将系统to配置更改为:
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";发布于 2016-06-28 15:15:35
对我有用的是以下几点
在systemjs.config.js中
在地图中添加:'ng2-select': 'node_modules/ng2-select'
在包中添加::'ng2-select': {main:'ng2-select.js', defaultExtension: 'js'}
然后像这样导入:import {SELECT_DIRECTIVES} from "ng2-select";
https://stackoverflow.com/questions/36274015
复制相似问题