无法向AngularJs Boilerplate添加新模块

时间:2017-03-22 05:00:02

标签: angularjs node.js

我正在开展一个角度项目,并决定使用样板。以下是样板文件的链接:https://github.com/jakemmarsh/angularjs-gulp-browserify-boilerplate

我面临的问题是我无法添加任何新的模板。

例如,我想通过npm添加ngCart。我已经安装了它,但代码中无法访问它。

@Entity
@Table(name="Map")
public class Map implements Serializable {

  private static final long serialVersionUID = -5527566248002296042L;

  @Id
  @Column(name = "id")
  @GeneratedValue(strategy=GenerationType.AUTO)
  private Integer mapId;

  @OneToMany(mappedBy = "mapId", cascade = CascadeType.ALL)
  private List<Car> cars;

  @Column(name = "address")
  private String address;

  public Integer getMapId() {
     return mapId;
  }

  public void setMapId(Integer mapId) {
     this.mapId = mapId;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  } 
  public List<Car> getCars() {
    return cars;
  }

  public void setCars(List<Car> cars) {
      this.cars= cars;
  }
}

我的package.json是

`import angular from 'angular';

// angular modules
import constants from './constants';
import onConfig  from './on_config';
import onRun     from './on_run';
import 'angular-ui-router';
import 'ngCart'; //this doesn't import it
import './templates';
import './filters';
import './controllers';
import './services';
import './directives';

// create and bootstrap application
const requires = [
  'ui.router',
  'ngCart',
  'templates',
  'app.filters',
  'app.controllers',
  'app.services',
  'app.directives'
];

// mount on window for testing
window.app = angular.module('app', requires);

angular.module('app').constant('AppSettings', constants);

angular.module('app').config(onConfig);

angular.module('app').run(onRun);

angular.bootstrap(document, ['app'], {
  strictDi: true
});

1 个答案:

答案 0 :(得分:4)

ngCart在其package.json中没有主键,在其根目录中也没有index.js,因此import无法知道要导入的内容。因此,您需要在import语句中更明确一些。

尝试替换

import 'ngCart'; //this doesn't import it

通过

import 'ngCart/dist/ngCart'; //this should do it ;)