2017-11-11 70 views
0

我試圖實現此角碼時,得到TypeError。它圍繞Class({constructor:function(){}})生成錯誤。我一直指出這(https://github.com/angular/angular/commit/cac130eff9b9cb608f2308ae40c42c9cd1850c4d),但不知道如何實施解決方案。重構代碼如何爲我amTypeError - Angular^5.0

我很想知道一種替代方案,因爲我是這種編碼技術的新手。

這是我最近購買的一本關於使用導軌,角度爲 和postgres的書籍。謝謝。

import "hello_angular/polyfills"; 

import { Component, NgModule } from "@angular/core"; 
import { BrowserModule   } from "@angular/platform-browser"; 
import { FormsModule   } from "@angular/forms"; 
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"; 

var CustomerSearchComponent = Component({ 
    selector: "shine-customer-search", 
    template: '\ 
<header> \ 
    <h1 class="h2">Customer Search</h1> \ 
</header> \ 
    ' 
}).Class({ 
    constructor: function() { 
    } 
}); 

var CustomerAppModule = NgModule({ 
    imports:  [ BrowserModule, FormsModule ], 
    declarations: [ CustomerSearchComponent ], 
    bootstrap: [ CustomerSearchComponent ] 
}) 
.Class({ 
    constructor: function() {} 
}); 

回答

0

據我瞭解在上面的鏈接的信息,您必須確定您的組件爲class,並與@Component裝飾裝飾。

@Component({ 
    selector: "shine-customer-search", 
  template: '\ 
<header> \ 
  <h1 class="h2">Customer Search</h1> \ 
</header> \ 
 ' 
}) 
export class CustomerSearchComponent { 
  constructor() { 
    } 
} 

編輯

您還可以使用 typescript。當您用 javascript標記您的問題時,這可能是您的問題。

你的模塊看起來就像這樣:

@NgModule({ 
    imports:  [ BrowserModule, FormsModule ], 
    declarations: [ CustomerSearchComponent ], 
    bootstrap: [ CustomerSearchComponent ] 
}) 
export class CustomerAppModule { } 
+0

**您也可以選擇使用打字稿**,不,這不是真的;) – Alex