2015-04-27 34 views
6

szablon Mam następnie prowadnicę Angular 2 Quickstart ale pojawia się następujący błąd:Błąd: Nie znaleziono MyAppComponent

Error during instantiation of Token(AppView)!. ORIGINAL ERROR: Error: No template found for MyAppComponent

To jest odpowiedni kod:

import {Component, View} from 'angular2/core'; 
import {bootstrap} from 'angular2/platform/browser' 
// Note I've changed Template to View here as I think it is a typo 

.... 

@View({ 
    template: '<h1>Hello {{ name }}</h1>' 
}) 

.... 

Po sugestię Duncana Bootha tutaj http://blog.ionic.io/angular-2-series-introduction/ I wprowadziliśmy poniższe zmiany i wszystko zadziałało:

import {Component, Template} from 'angular2/core'; 
import {bootstrap} from 'angular2/platform/browser'; 

.... 

@Template({ 
    inline: "<h1>Hello {{ name }}</h1>" 
}) 

.... 

Ale yesimahum Komentarz w tym samym linku wspomina, że ​​"Widok jest nową składnią", która wydaje się być taka, jak jest pokazana w Plunker z Angular 2 Step by Step Guide.

Dlaczego więc kod Szybki start rzuca błąd i jaka jest poprawna poprawka?

Odpowiedz

1

myślę, że trzeba to sprawdzić

import {Component, Template, bootstrap} from 'angular2/angular2'; 

@Component({ 
    selector: 'my-app' 
}) 
@Template({ 
    inline: '<h1>Hello {{ name }}</h2>' 
}) 

class MyAppComponent { 
    constructor() { 
     this.name = 'Alice'; 
    } 
} 

bootstrap(MyAppComponent); 
+0

W moim pytaniu celowo pokazałem tylko odpowiedni kod i mówię również, że Widok i ** nie ** Szablon to nowa składnia. –

+0

Całkowicie rozumiem, co powiedziałeś .. ponieważ to jest to, co jest w dokumentach .... Nie wiem, dlaczego to nie działa na teraz –

0

I właśnie wyjaśnienie: jeśli trzeba zawierać pewne wskazówki, należy zrobić to w ten sposób:

import {Component, Template, View, CSSClass, NgFor, bootstrap} from 'angular2/angular2'; 

// Component annotations .. 
@Component({ 
    selector: 'my-app' 
}) 
@Template({ 
    url: 'templates/layout.html' 
}) 
@View({ 
    directives: [CSSClass, NgFor] 
}) 

a następnie w kod możesz użyć [klasa], * ng-for, etc :)

Powiązane problemy