【问题标题】:Angular2 + ng-bootstrap on server side templates服务器端模板上的 Angular2 + ng-bootstrap
【发布时间】:2017-02-04 09:18:42
【问题描述】:

我的服务器端应用程序上有带有 ng-bootstrap 的 Angular2 (2.0.0)。所有的模板都是用 php 渲染的(不是 angular)。

当我从服务器端包含任何 ng-bootstrap sn-p 时,它不起作用。但是,如果我将它们从 <app-root>...</app-root> 中的角度模板中包含在内,那么它就可以工作。

我基本上需要在模板的任何位置包含下拉、模态、警报...作为直接指令样式。这怎么可能?

<body>

<h1>Title 1</h1>

<p>This is para...</p>

<app-root></app-root> <!-- any ng-bootstrap directives are accessable inside app-root -->

<!-- I'm not rendered as ng-bootstrap directive, since its not inside app-root -->
<ngb-alert [dismissible]="false">
    <strong>Warning!</strong> Better check yourself, you're not looking too good.
</ngb-alert>


 <!--script tags are included here for angular2-->

</body>

【问题讨论】:

  • 您需要提供一些具体的代码示例。
  • 添加代码示例
  • 好吧,把它放在app-root下,否则app-root就不是你的app root了。
  • 我怎么能把它放在 app-root 之外,因为 90% 的应用程序和模板是从服务器生成的。
  • 我不明白服务器生成模板这一事实如何阻止它生成警报位于应用程序根内部而不是外部的模板。你需要解释一下。

标签: twitter-bootstrap angular angular2-template angular2-directives ng-bootstrap


【解决方案1】:

如果你想要一个 Angular2 组件作为&lt;body&gt; 的直接子组件,你必须引导它。这意味着您需要一个NgModule,该组件位于bootstrap: [NgbAlert],然后调用platform.bootstrapModule(NgbAlertModule)。 这会在您的页面上为每个引导模块创建一个新的 Angular2 应用程序。

【讨论】:

  • 我应该从哪里导入platform.bootstrapModule
  • “包含在引导程序中”是什么意思?你能编辑你的问题并在那里添加更新的代码吗?
  • 正如错误消息所说,Alert 不是一个组件。你不能引导指令。
  • 什么是NgbAlert
  • 对不起,没有想法。
猜你喜欢
  • 2011-05-11
  • 2014-04-06
  • 2017-08-09
  • 2012-02-11
  • 2020-10-11
  • 2012-10-27
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多