在angular2 app中集成ng2-select的问题

时间:2016-04-03 12:56:34

标签: angular

我试图将angular2指令集成到我的项目中; ng2-从here中选择,但我正在努力整合它。

在我的index.html文件中,我配置像这样的Systemjs

System.config({
            map: {
                'ng2-select': 'node_modules/ng2-select'
            },
            packages: {
                app: {
                    format: 'register',
                    defaultExtension: 'js'
                },
                'ng2-select': {
                    defaultExtension: 'js'
                }
            }
        });

        System.import('app/main').
        then(null, console.error.bind(console));

像我这样导入我的组件

import {Select} from 'ng2-select/ng2-select';

@Component({
    selector: 'movie',
    templateUrl: 'templates/movie.html',
    directives: [Select, FORM_DIRECTIVES, NgClass]
})

exports class MovieComponent {}

运行它,我收到此错误

angular2-polyfills.js:332 Error: SyntaxError: Unexpected token <(…)ZoneDelegate.invoke @ angular2-polyfills.js:332Zone.run @ angular2-polyfills.js:227(anonymous function) @ angular2-polyfills.js:576ZoneDelegate.invokeTask @ angular2-polyfills.js:365Zone.runTask @ angular2-polyfills.js:263drainMicroTaskQueue @ angular2-polyfills.js:482$ @ system-polyfills.src.js:1340H @ system-polyfills.src.js:1340R.when @ system-polyfills.src.js:1340T.run @ system-polyfills.src.js:1340t._drain @ system-polyfills.src.js:1340drain @ system-polyfills.src.js:1340e @ system-polyfills.src.js:1340

查看网络检查器,它显示模块的js文件已加载,所以我不知道为什么我会一直收到此错误。

2 个答案:

答案 0 :(得分:0)

您无需在packages块中为ng2-select定义条目。在map块中,它就足够了:

System.config({
  map: {
    'ng2-select': 'node_modules/ng2-select'
  },
  packages: {
    app: {
      format: 'register',
      defaultExtension: 'js'
    }/*,
    'ng2-select': { // <-----
      defaultExtension: 'js'
    }*/
  }
});

有关详细信息,请参阅此问题:

答案 1 :(得分:0)

我在systemjs.config.js解决方案中配置:

import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass} from '@angular/common';
import {SELECT_DIRECTIVES} from 'ng2-select/ng2-select';

然后我导入了我的组件

testCreateItem_throwsItemServiceBusinessException(impl.ItemServiceImplTest)  Time elapsed: 1.771 sec  <<< ERROR!
java.util.ServiceConfigurationError: org.togglz.core.spi.LogProvider: 
Provider org.togglz.slf4j.Slf4jLogProvider not a subtype