angular2 ng2-bs3-modal无法使用脚本标记加载

angular2 ng2-bs3-modal无法使用脚本标记加载,angular,modal-dialog,ng2-bootstrap,Angular,Modal Dialog,Ng2 Bootstrap,我有一个Angular 2应用程序,可以正常工作,我想向它添加modals,所以我执行了安装说明,就像Doug在这里说的那样: 说明中说使用index.html页面中的script标记 加载库或使用系统加载程序。因为所有其他模块都是通过脚本标签加载的,所以我也为这个模块加载了脚本标签 在我的组件内部,导入在VSCode中似乎可以识别,因为它显示了ng2-bs3-modal具有的各种项目,并且在编辑模式中没有显示任何错误 但是,当我尝试运行应用程序时,它没有运行,开发人员工具显示它正在尝试对/ng

我有一个Angular 2应用程序,可以正常工作,我想向它添加modals,所以我执行了安装说明,就像Doug在这里说的那样:

说明中说使用index.html页面中的script标记 加载库或使用系统加载程序。因为所有其他模块都是通过脚本标签加载的,所以我也为这个模块加载了脚本标签

在我的组件内部,导入在VSCode中似乎可以识别,因为它显示了ng2-bs3-modal具有的各种项目,并且在编辑模式中没有显示任何错误

但是,当我尝试运行应用程序时,它没有运行,开发人员工具显示它正在尝试对/ng2-bs3-modal/ng2-bs3-modal进行http调用。所有导入的模块都包含在node_modules文件夹中,因此我不确定为什么1)此http调用是从组件进行的,以及2)为什么它将从根文件夹而不是node_modules文件夹进行查看

在页面加载时,开发工具控制台日志中显示的错误为:

GET http://localhost:3000/ng2-bs3-modal/ng2-bs3-modal 404 (Not Found)   angular2/polyfills.js
Error: XHR error (404 Not Found) loading http://localhost:3000/ng2-bs3-modal/ng2-bs3-modal(…)  angular2/polyfills.js
html-正如我所说,在尝试添加模态之前,一切都正常。我使用的是脚本标记包含,而不是系统版本,下面包含了整个index.html文件

<!DOCTYPE html>
<html lang="en">

<head>
<title></title>
<base href="/">

<script data-require="jquery@*" data-semver="2.2.0" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script data-require="bootstrap@*" data-semver="3.3.6" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">   </script>


<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js">
</script>

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="public/js/bundle.js"></script>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/local.css" rel="stylesheet">

<script>
    System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('main')
        .then(null, console.error.bind(console));
</script>

<script src="node_modules/ng2-bs3-modal/bundles/ng2-bs3-modal.js"></script>

</head>
<base href="/">
<body>
<app>Loading...</app>
</body>

</html>
如果我从组件中删除ng2-bs3-modal导入,一切都会像以前一样正常运行


所有的演示和示例都有index.html文件,其中js文件通过system.config加载,因此我想知道这是否曾在使用说明中提到的脚本标记加载时进行过测试。

我会在包含system.config和system.import的脚本块之前移动ng2-bs3-modal.js文件的脚本元素:

<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="public/js/bundle.js"></script>

<script src="node_modules/ng2-bs3-modal/bundles/ng2-bs3-modal.js"></script>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/local.css" rel="stylesheet">

<script>
    System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('main')
        .then(null, console.error.bind(console));
</script>

System.config({
包:{
应用程序:{
格式:'寄存器',
defaultExtension:'js'
}
}
});
System.import('main')
.then(null,console.error.bind(console));

我会将ng2-bs3-modal.js文件的脚本元素移动到包含System.config和System.import的脚本块之前:

<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="public/js/bundle.js"></script>

<script src="node_modules/ng2-bs3-modal/bundles/ng2-bs3-modal.js"></script>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/local.css" rel="stylesheet">

<script>
    System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('main')
        .then(null, console.error.bind(console));
</script>

System.config({
包:{
应用程序:{
格式:'寄存器',
defaultExtension:'js'
}
}
});
System.import('main')
.then(null,console.error.bind(console));

我终于找到了问题所在。ng2-bs3-modal npm试图在构建期间运行tslint,即使tslint未包括在内。因此,在查看npm日志并看到构建错误后,我继续安装了tslint并重新安装了ng2-bs3-modal npm,一切正常。

我终于找到了问题所在。ng2-bs3-modal npm试图在构建期间运行tslint,即使tslint未包括在内。因此,在查看npm日志并看到构建错误后,我继续安装了tslint并重新安装了ng2-bs3-modal npm,一切正常。

您能在问题中添加SystemJS配置和HTML条目文件的内容吗?谢谢这篇文章已经更新,显示了现有的工作系统配置。你能在问题中添加你的SystemJS配置和HTML条目文件的内容吗?谢谢这篇文章已经更新,显示了现有的工作系统配置。是的,这是我最初使用它的地方,但是把它放在那里,除了其他错误之外,还会出现这个错误ReferenceError:System未定义(匿名函数)@ng2-bs3-modal.js:10I已将脚本加载程序行severla在index.html文件中上下移动,它会给出不同的错误,但从未起作用。我注意到其他人对此模块有问题,他们最终使用系统加载器。我不确定这个模块是否使用说明书中提到的脚本标记加载程序进行过全面测试。所以我放弃了脚本加载程序,继续使用系统加载程序。它似乎在index.html中很好地加载了模块,并在组件中得到识别。然而,ng2-bs3-modal模块本身却抱怨无法找到自己的需求。/component/modal.:ReferenceError:require未定义(…),它显示::at eval(),即:var modal_1=require('./组件/modal');是的,那是我最初使用它的地方,但是把它放在那里除了其他错误之外,还会产生这个错误ReferenceError:System未定义(匿名函数)@ng2-bs3-modal.js:10I已将脚本加载程序行severla在index.html文件中上下移动,它会给出不同的错误,但从未起作用。我注意到其他人对此模块有问题,他们最终使用系统加载器。我不确定这个模块是否使用说明书中提到的脚本标记加载程序进行过全面测试。所以我放弃了脚本加载程序,继续使用系统加载程序。它似乎在index.html中很好地加载了模块,并在组件中得到识别。然而,ng2-bs3-modal模块本身却抱怨无法找到自己的需求。/component/modal.:ReferenceError:require未定义(…),它显示::at eval(),即:var modal_1=require('./组件/modal');