簡體   English   中英

Angular2 Selector與bundle和ECM6的任何元素都不匹配

[英]Angular2 Selector did not match any elements with bundle and ECM6

我有一個非常簡單的angular2項目,配置為與Gulp,Bundle和ECM6一起使用。 Bundle將創建一個大文件,其中包含角度加上我的應用程序的翻譯ECM5。

<!DOCTYPE html>
<html>
<head>
    <title>Angular 2 Test</title>
    <script src="bundle.js"></script>
</head>

<body>
<mainapp>

</mainapp>
</body>
</html>

角度應用程序定義如下:

import {Component, View, bootstrap} from 'angular2/core';

export class mainComponent {
    static get annotations() {
        return [
            new Component({
                selector: 'mainapp'
            }),
            new View({
                template: `<div>Hello!</div>`
            })
        ];
    }
}

bootstrap(mainComponent);

但是當我加載它時,我繼續收到錯誤

"selector 'mainapp' did not match any element"

問題是我在HTML中定義了mainapp組件之前包含了bundle.js 這解決了這個問題。

<!DOCTYPE html>
<html>
<head>
    <title>Angular 2 Test</title>

</head>

<body>
<mainapp>

</mainapp>
<script src="bundle.js"></script>
</body>
</html>

更新:

<script src="bundle.js" defer></script>

無論元素的順序如何,似乎也解決了問題。

暫無
暫無

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

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