0

Angularjs 2教程描述了如何在 TypeScript 上为组件设置输入变量

export class HeroDetailComponent {
  @Input()
  hero: Hero;
}

由于 javascipt 的文档尚不可用,我坚持通过 javascript 设置组件变量,这里是应该接收 hero 变量作为输入的组件的代码,我可以设置它吗?

(function (app) {
    app.HeroDetailComponent = ng.core.Component({
        selector: 'hero-detail',
        template: `<div *ngIf="selectedHero">
        <h2>{{selectedHero.name}} details!</h2>
                <div><label>id: </label>{{selectedHero.id}}</div>
                <div>
                    <label>name: </label>
                    <input [(ngModel)]="hero.name" placeholder="name"/>
                </div>
                </div>`
    })
    .Class({
        constructor: function(){

        }
    })
})(window.app || (window.app = {}));

使用组件<hero-detail [hero]="selectedHero"></hero-detail> 由于未设置 属性hero浏览器触发以下错误Can't bind to 'hero' since it isn't a known property of 'hero-detail'

4

0 回答 0