Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: No template found for MyAppComponent

Tags:

angularjs

I've followed the Angular 2 Quickstart guide but get the following error:

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

This is the relevant code:

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>'
})

....

Following Duncan Booth's suggestion here http://blog.ionic.io/angular-2-series-introduction/ I made the changes below and everything works:

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

....

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

....

But yesimahuman's comment at the same link mentions that "View is the new syntax" which does seem to be the case as is shown in the Plunker from the Angular 2 Step by Step Guide.

So why is the Quickstart code throwing an error and what is the correct fix?

like image 613
camden_kid Avatar asked Apr 27 '15 15:04

camden_kid


1 Answers

I think you need to check this out

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);
like image 125
Solomon Ayoola Avatar answered Oct 14 '22 01:10

Solomon Ayoola