angular.js - angular introduces dependent modules
滿天的星座
滿天的星座 2017-05-15 17:12:42
0
2
665

package.json: as follows

{
  "name": "tengai-medical",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack && webpack-dev-server --hot --inline"
  },
  "author": "Irene Tang",
  "license": "ISC",
  "devDependencies": {
    "angular": "^1.2.27",
    "angular-bootstrap": "0.12.2",
    "css-loader": "^0.24.0",
    "file-loader": "^0.9.0",
    "html-webpack-plugin": "^2.22.0",
    "node-sass": "^3.8.0",
    "requirejs": "2.1.15",
    "sass-loader": "^4.0.0",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.7",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.15.1"
  }
}

index.js

var angular = require('angular');
var bootstrap = require('angular-bootstrap');
angular.element(document).ready(function() {
  var app = angular.module('multi-bootstrap', ['ui-bootstrap']);
  app.controller('myController', ['$scope', '$modal', function($scope, $modal) {
  }]);
  angular.bootstrap(document, ['multi-bootstrap']);
})

现在我定义的myController需要用到$modal服务,这个服务在angular-bootstrap里,为什么require('angular')能拿到angular,require('angular-bootstrap')拿到的却是个空对象???新建模块的时候该怎么引入依赖模块???
滿天的星座
滿天的星座

reply all(2)
仅有的幸福
var angular = require('angular');
require('angular-bootstrap/ui-bootstrap');
angular.element(document).ready(function() {
  var app = angular.module('multi-bootstrap', ['ui.bootstrap']);
  app.controller('myController', ['$scope', '$modal', function($scope, $modal) {
  }]);
  angular.bootstrap(document, ['multi-bootstrap']);
})

angular-bootstrap is a folder under node_modules, which contains a js file of ui-bootstrap. Angular must be introduced first before require('angular-bootstrap/ui-bootstrap') is introduced, because it depends on angular. Finally When using it, it is ui.bootstrap instead of ui-bootstrap, because the module name defined in ui-bootstrap is ui.bootstrap

仅有的幸福

I think your package may be wrong, please change it to angular-ui-bootstrap.
You can look at the source code. There is the export keyword in angular, but there is no export in angular-bootstrap

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template