import { Component, FormView, Model } from "../../../src/core"; import { HeroNameCollection } from "../Collection/HeroName"; import { HeroPowerCollection } from "../Collection/HeroPower"; @Component({ el: "ng-hero", events: { "submit form": "onSubmitForm" }, collections: { names: new HeroNameCollection(), powers: new HeroPowerCollection() }, template: `
Name is required
Power is required
` }) export class HeroView extends FormView { el: HTMLElement; collections: NgBackbone.CollectionMap; initialize() { this.collections.get( "powers" ).fetch(); this.collections.get( "names" ).fetch(); this.render(); } onSubmitForm( e:Event ){ let el = e.target; e.preventDefault(); let collection = this.collections.get( "heroes" ), data = this.getData( "hero" ); el.reset(); this.reset( "hero" ); if ( data[ "name" ] ) { collection.create( data, { error: console.error }); } } }