ng2引导模式不能打开模式



我有一个类似的pizza.com组件

import {Component,ViewContainerRef} from '@angular/core';
import { CORE_DIRECTIVES } from '@angular/common';
import { BUTTON_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
import {MODAL_DIRECTIVES, BS_VIEW_PROVIDERS} from 'ng2-bootstrap/ng2-bootstrap';
@Component({
  selector: 'pizza-com',
  templateUrl: './app/pizza/pizza.html',
  directives: [BUTTON_DIRECTIVES,MODAL_DIRECTIVES,CORE_DIRECTIVES],
  viewProviders:[BS_VIEW_PROVIDERS],
})
export class PizzaComponent {
    public constructor(viewContainerRef:ViewContainerRef) {
    // You need this small hack in order to catch application root view container ref
    this.viewContainerRef = viewContainerRef; <<<---this doesn't seems to work dunno why
  }
}

和我的pizza.html像这个

<!-- Large modal -->
<button class="btn btn-primary" (click)="lgModal.show()">Large modal</button>
<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" (click)="lgModal.hide()" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title">Large modal</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
    </div>
  </div>
</div>

当我按下模式按钮时,它显示错误

platform-browser.umd.js:1900 
EXCEPTION: Error: Uncaught (in promise): 
TypeError: Cannot read property 'parentInjector' of undefined

我做错了什么?

我也遵循ng2引导程序中的示例,但this.viewContainerRef似乎不起作用

我使用Angular 2 Final/ng2 bootstrap 1.1.3/systemjs

import { Component, ViewContainerRef } from '@angular/core';
@Component({
  selector: 'app-root',
  template: '<router-outlet></router-outlet>',
  encapsulation: ViewEncapsulation.None
})
export class AppComponent implements OnInit {
  private viewContainerRef: ViewContainerRef;
  constructor(viewContainerRef: ViewContainerRef) {
    this.viewContainerRef = viewContainerRef;
  }
}

相关内容

  • 没有找到相关文章

最新更新