簡體   English   中英

角度4“未捕獲錯誤:區域已加載。”使用模態對話框引導程序

[英]Angular 4 “Uncaught Error: Zone already loaded.” using modal dialog bootstrap

我嘗試使用帶路由器出口角度4的模態對話框引導程序並獲得錯誤“未捕獲錯誤:區域已加載”。

這是我的腳本:master-golongan.component.ts

import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
import { Title } from '@angular/platform-browser';

@Component({
  selector: 'app-master-golongan',
  templateUrl: './master-golongan.component.html',
  styleUrls: ['./master-golongan.component.css'],
})
export class MasterGolonganComponent implements OnInit {

  golList: any;
  constructor(private title: Title) {
    this.title.setTitle('Daftar Golongan | Inventory Management System');
  }

  ngOnInit() {
  }

}

主golongan.component.html

    <a class="btn btn-success  btn-xs " data-toggle="modal" data-target="#myModal" routerLinkActive="active"
      routerLink="new-edit-golongan">
      <i class="fa fa-plus"></i> Golongan Baru</a>


<div class="modal" id="myModal">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <router-outlet></router-outlet>
    </div>
  </div>
</div>

新編輯golongan.component.html

<div class="modal-body">
  <p>Some text in the modal.</p>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

並有如下圖所示的錯誤

在此輸入圖像描述

如何在模態對話框引導程序中調用router-outlet angular 4? 怎么解決?

我在角度應用程序中遇到了相同的modal-popup問題,我找到了一個解決方案:你需要將代碼更改為master-golongan.component.html文件:

不要使用'routerLink'而不是'href'進行數據切換模式,只需更改'href'而不是'routerLink'並檢查其工作情況:

<a class="btn btn-success  btn-xs " data-toggle="modal" data-target="#myModal" routerLinkActive="active"
  href="new-edit-golongan">
  <i class="fa fa-plus"></i> Golongan Baru</a>

得到了同樣的問題, https://github.com/angular/angularfire2/issues/1597幫我刪除了這個錯誤。 只需評論或刪除import 'zone.js'; 來自node_modules / angularfire2 / angularfire2.d.ts。 它對我有用。

問題是,一旦angular有全局定義的zone.js,那么就不必再次導入zone.js了。 我正在使用: "angularfire2": "5.0.0-rc.4"

在你的node_modules/angularfire2/angularfire2.d.ts ,刪除以下行import 'zone.js/dist/zone'; 它會工作:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM