Angularjs 错误:找不到MyAppComponent的模板

Angularjs 错误:找不到MyAppComponent的模板,angularjs,Angularjs,我遵循了指南,但出现以下错误: 令牌(AppView)实例化期间出错!。原始错误:错误: 未找到MyAppComponent的模板 以下是相关代码: 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 .... @V

我遵循了指南,但出现以下错误:

令牌(AppView)实例化期间出错!。原始错误:错误: 未找到MyAppComponent的模板

以下是相关代码:

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

....
从'angular2/core'导入{Component,View};
从“angular2/platform/browser”导入{bootstrap}
//注意,我已将模板更改为在此处查看,因为我认为这是一个打字错误
....
@看法({
模板:“你好{{name}”
})
....
根据Duncan Booth的建议,我做了以下更改,一切正常:

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

....

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

....
从'angular2/core'导入{Component,Template};
从'angular2/platform/browser'导入{bootstrap};
....
@模板({
内联:“你好{{name}”
})
....
但是yesimahuman在同一链接上的评论提到“视图是新的语法”,这似乎确实是从


那么,为什么快速启动代码会抛出错误,正确的修复方法是什么呢?

我想您需要检查一下

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);
从'angular2/angular2'导入{组件、模板、引导程序};
@组成部分({
选择器:“我的应用程序”
})
@模板({
内联:“你好{{name}”
})
类MyAppComponent{
构造函数(){
this.name='Alice';
}
}
bootstrap(MyAppComponent);

我只是想澄清一下:如果您需要包含一些指令,您应该这样做:

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

然后在代码中,您可以使用[class]、*ng for等:)

在我的问题中,我故意只展示了相关的代码,我还说视图而不是模板是新语法。我完全理解您所说的。。因为这就是文档中的内容。。。。我不知道为什么它现在不起作用